Skip to content

Commit 2c330b8

Browse files
m-nashscbedd
andauthored
Initial checkin for source generator (Azure#49088)
* Enhance ModelReaderWriter with collection support Updated ModelReaderWriter.cs to improve reading and writing functionality for various collection types, including List<> and Dictionary<>. Added error handling for unsupported types and enhanced exception messages. Updated ModelReaderWriterTests.cs with new test cases to validate the changes, covering edge cases and empty collections. Added JSON test data for comprehensive testing of availability set data. Included a new package reference for System.Memory.Data in project files. Minor corrections made to comments and variable names for clarity. * expand test coverage * update api * update dotnet in ci * add aot annotations * more aot annotation * Update to keep current behavior but add new read methods which are AOT compatible for IEnumerable and IPersistableModel * fix aot on collection reader * update to remove collection read type restriction * update context pattern * drop internal interface * add ROM support * add immutablelist test example * add more test cases * code clean up * add coverage for context and non context into modeltests * refactor collection tests to use common base * update api * move list of list tests to inherit test base * update remaining tests * more test coverage * add remaining immutable and readonly tests * add perf tests to verify no regression and context path is faster * fix net framework test diff * add polymorphic collection tests * comment out problematic tests * pr fb * pr feedback to remove CollectionBuilder as a public class * more api feedback * fix param name * drop property funcs * drop assert key * drop asserts and createelementinstance * add support and test cases for null entries in the collections add tests for custom collection * add support and tests for non generic collection and non string keys * Fill out coverage after refactors * update method names to match new renames * added test cases for mixed model and enumerable * initial checkin for source generator * update api * update after merge * add rom * fill in invocation cases and add tests * update api * update eventgrid source generator to use new common build props * update another reference to eventgrid SG * clean up code * add some doc placeholders * update docs and links * fix test cases * update api * update to non relative links * fix links * use file scoped namespace * collapse polyfil folder structure * rename unit test project * fix typo in link * fill out code coverage * capitalization * updating eng/service proj to exclude SourceGeneration by default during builds --------- Co-authored-by: Scott Beddall <[email protected]>
1 parent 16d360f commit 2c330b8

File tree

135 files changed

+4192
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+4192
-647
lines changed

eng/Directory.Build.Common.props

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
<IsGeneratorLibrary Condition="'$(IsGeneratorLibrary)' == '' and $(MSBuildProjectName.StartsWith('Azure.Generator'))">true</IsGeneratorLibrary>
1515
<IsClientLibrary Condition="'$(IsClientLibrary)' == '' and $(MSBuildProjectName.StartsWith('Azure.'))">true</IsClientLibrary>
1616
<IsFunctionsLibrary Condition="'$(IsFunctionsLibrary)' == '' and $(MSBuildProjectName.StartsWith('Microsoft.Azure.WebJobs.Extensions.'))">true</IsFunctionsLibrary>
17+
<IsSourceGenerator Condition="'$(IsSourceGenerator)' == '' and $(MSBuildProjectName.EndsWith('.SourceGeneration'))">true</IsSourceGenerator>
1718

1819
<IsTestProject Condition="'$(IsTestProject)' == '' and $(MSBuildProjectName.EndsWith('.Tests'))">true</IsTestProject>
1920
<IsSamplesProject Condition="'$(IsSamplesProject)' == '' and $(MSBuildProjectName.EndsWith('.Samples'))">true</IsSamplesProject>
2021
<IsPerfProject Condition="'$(IsPerfProject)' == '' and $(MSBuildProjectName.EndsWith('.Perf'))">true</IsPerfProject>
2122
<IsStressProject Condition="'$(IsStressProject)' == '' and $(MSBuildProjectName.EndsWith('.Stress'))">true</IsStressProject>
2223
<IsTestSupportProject Condition="'$(IsTestSupportProject)' == '' and '$(IsTestProject)' != 'true' and ($(MSBuildProjectDirectory.Contains('/tests/')) or $(MSBuildProjectDirectory.Contains('\tests\')))">true</IsTestSupportProject>
2324
<IsShippingLibrary Condition="'$(IsShippingLibrary)' == '' and '$(IsTestProject)' != 'true' and '$(IsTestSupportProject)' != 'true' and '$(IsPerfProject)' != 'true' and '$(IsSamplesProject)' != 'true' and '$(IsStressProject)' != 'true'">true</IsShippingLibrary>
24-
<IsShippingClientLibrary Condition="'$(IsClientLibrary)' == 'true' and '$(IsShippingLibrary)' == 'true'">true</IsShippingClientLibrary>
25+
<IsShippingClientLibrary Condition="'$(IsClientLibrary)' == 'true' and '$(IsShippingLibrary)' == 'true' and '$(IsSourceGenerator)' != 'true'">true</IsShippingClientLibrary>
2526
<TestFrameworkSupportFiles>$(MSBuildThisFileDirectory)/../sdk/core/Azure.Core.TestFramework/src/Shared/*.cs</TestFrameworkSupportFiles>
2627

2728
<IncludeOperationsSharedSource Condition="'$(IncludeOperationsSharedSource)' == '' and '$(IsMgmtLibrary)' == 'true' and '$(IsTestProject)' != 'true' and '$(IsPerfProject)' != 'true'">true</IncludeOperationsSharedSource>
@@ -136,8 +137,9 @@
136137
<SupportsNetStandard20 Condition="'$(SupportsNetStandard20)' == ''">false</SupportsNetStandard20>
137138

138139
<RequiredTargetFrameworks>net452;net461;netstandard2.0</RequiredTargetFrameworks>
139-
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true'">net8.0;netstandard2.0</RequiredTargetFrameworks>
140+
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true' and '$(IsSourceGenerator)' != 'true'">net8.0;netstandard2.0</RequiredTargetFrameworks>
140141
<RequiredTargetFrameworks Condition="'$(IsGeneratorLibrary)' == 'true'">net8.0</RequiredTargetFrameworks>
142+
<RequiredTargetFrameworks Condition="'$(IsSourceGenerator)' == 'true'">netstandard2.0</RequiredTargetFrameworks>
141143
</PropertyGroup>
142144

143145
<PropertyGroup Condition="'$(IsGeneratorLibrary)' != 'true' and ('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsSamplesProject)' == 'true' or '$(IsPerfProject)' == 'true' or '$(IsStressProject)' == 'true')">
@@ -164,6 +166,13 @@
164166
<DefineConstants Condition="'$(IsTargetingNetFx)' == 'true'">$(DefineConstants);FullNetFx</DefineConstants>
165167
</PropertyGroup>
166168

169+
<!-- SourceGeneration common settings -->
170+
<PropertyGroup Condition="'$(IsSourceGenerator)' == 'true'">
171+
<OutputItemType>Analyzer</OutputItemType>
172+
<AnalyzerLanguage>cs</AnalyzerLanguage>
173+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
174+
</PropertyGroup>
175+
167176
<!-- Common library and package properties -->
168177
<PropertyGroup>
169178
<Company>Microsoft Corporation</Company>

eng/Packages.Data.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@
279279
<PackageReference Update="Azure.ClientSdk.Analyzers" Version="0.1.1-dev.20250310.1" PrivateAssets="All" />
280280
<PackageReference Update="coverlet.collector" Version="3.2.0" PrivateAssets="All" />
281281
<!-- Note: Upgrading the .NET SDK version needs to be synchronized with the autorest.csharp repository -->
282-
<PackageReference Update="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" PrivateAssets="All" />
282+
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="All"/>
283283
<PackageReference Update="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.2" PrivateAssets="All" />
284+
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version ="4.12.0" PrivateAssets="All" />
285+
<PackageReference Update="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" PrivateAssets="All" />
284286
<PackageReference Update="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.20467.1" PrivateAssets="All" />
285287
<PackageReference Update="Microsoft.DotNet.GenAPI" Version="5.0.0-beta.19552.1" PrivateAssets="All" />
286288
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
287289
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
288290
<PackageReference Update="SauceControl.InheritDoc" Version="1.2.0" PrivateAssets="All" />
289291
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.333" PrivateAssets="All" />
290-
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version ="3.9.0" PrivateAssets="all" />
291292
</ItemGroup>
292293

293294
<!--

eng/service.proj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<IncludeSamples Condition="'$(IncludeSamples)' == ''">true</IncludeSamples>
1010
<IncludePerf Condition="'$(IncludePerf)' == ''">true</IncludePerf>
1111
<IncludeStress Condition="'$(IncludeStress)' == ''">true</IncludeStress>
12+
<IncludeSourceGeneration Condition="'$(IncludeSourceGeneration)' == ''">false</IncludeSourceGeneration>
1213
<IncludeIntegrationTests Condition="'$(IncludeIntegrationTests)' == ''">true</IncludeIntegrationTests>
1314
<IncludeSamplesApplications Condition="'$(IncludeSamplesApplications)' == ''">true</IncludeSamplesApplications>
1415
<IncludeSamplesApplications Condition="'$(ServiceDirectory)' != '*' or '$(IncludeSamples)' == 'false'">false</IncludeSamplesApplications>
@@ -50,20 +51,23 @@
5051
<PerfProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\perf\**\*.csproj" />
5152
<StressProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\stress\**\*.csproj" />
5253
<SampleApplications Include="..\samples\**\*.csproj" />
54+
<SourceGenerationProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\gen\**\*.csproj" />
5355
<SrcProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\src\**\*.csproj" Exclude="@(TestProjects);@(SamplesProjects);@(PerfProjects);@(StressProjects)" />
5456
<ProjectReference Include="@(TestProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeTests)' == 'true'" />
5557
<ProjectReference Include="@(SamplesProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeSamples)' == 'true'" />
5658
<ProjectReference Include="@(PerfProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludePerf)' == 'true'" />
5759
<ProjectReference Include="@(StressProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeStress)' == 'true'" />
5860
<ProjectReference Include="@(SampleApplications)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeSamplesApplications)' == 'true'"/>
5961
<ProjectReference Include="@(SrcProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeSrc)' == 'true'" />
62+
<ProjectReference Include="@(SourceGenerationProjects)" Exclude="@(MgmtExcludePaths)" Condition="'$(IncludeSourceGeneration)' == 'true'" />
6063
</ItemGroup>
6164

6265
<Import Project="..\sdk\$(ServiceDirectory)\*.projects" />
6366
<Import Project="$(RepoRoot)$(ProjectListOverrideFile)" Condition="'$(ProjectListOverrideFile)' != '' " />
6467

6568
<ItemGroup Condition="'$(ProjectListOverrideFile)' != '' and '$(EnableOverrideExclusions)' != ''">
6669
<TestProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\tests\**\*.csproj" Exclude="@(MgmtExcludePaths)" />
70+
<SourceGenerationProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\gen\**\*.csproj" Exclude="@(MgmtExcludePaths)" />
6771
<SamplesProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\samples\**\*.csproj;..\sdk\$(ServiceDirectory)\samples\**\*.csproj" Exclude="@(MgmtExcludePaths)" />
6872
<PerfProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\perf\**\*.csproj" Exclude="@(MgmtExcludePaths)" />
6973
<StressProjects Include="..\sdk\$(ServiceDirectory)\$(Project)\stress\**\*.csproj" Exclude="@(MgmtExcludePaths)"/>
@@ -79,6 +83,7 @@
7983
<ProjectReference Remove="@(SrcProjects)" Condition="'$(IncludeSrc)' == 'false'" />
8084
<ProjectReference Remove="@(IntegrationTestProjects)" Condition="'$(IncludeIntegrationTests)' == 'false'" />
8185
<ProjectReference Remove="@(SharedProjects)" Condition="'$(IncludeSrc)' == 'false'" />
86+
<ProjectReference Remove="@(SourceGenerationProjects)" Condition="'$(IncludeSourceGeneration)' == 'false'" />
8287
</ItemGroup>
8388

8489
<!-- Remove all projects except the ones included by the SDKType filter -->

sdk/core/Azure.Core/Azure.Core.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ClientModel.Tests.In
6363
EndProject
6464
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ClientModel.Tests", "..\System.ClientModel\tests\System.ClientModel.Tests.csproj", "{F317D37D-AA38-4557-A724-6ADA56281B77}"
6565
EndProject
66+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ClientModel.SourceGeneration", "..\System.ClientModel\gen\System.ClientModel.SourceGeneration.csproj", "{BBE55E49-F4CA-4EBD-C093-F8935A86C03F}"
67+
EndProject
68+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ClientModel.SourceGeneration.Tests", "..\System.ClientModel\tests\gen\System.ClientModel.SourceGeneration.Tests.csproj", "{F34B21B1-A3FC-5284-DBB8-1188EAA04B83}"
69+
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ClientModel.SourceGeneration.Unit.Tests", "..\System.ClientModel\tests\gen.unit\System.ClientModel.SourceGeneration.Unit.Tests.csproj", "{6ED66F0E-C7FA-3F0E-38C8-D576D48C8A58}"
71+
EndProject
6672
Global
6773
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6874
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +167,18 @@ Global
161167
{F317D37D-AA38-4557-A724-6ADA56281B77}.Debug|Any CPU.Build.0 = Debug|Any CPU
162168
{F317D37D-AA38-4557-A724-6ADA56281B77}.Release|Any CPU.ActiveCfg = Release|Any CPU
163169
{F317D37D-AA38-4557-A724-6ADA56281B77}.Release|Any CPU.Build.0 = Release|Any CPU
170+
{BBE55E49-F4CA-4EBD-C093-F8935A86C03F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
171+
{BBE55E49-F4CA-4EBD-C093-F8935A86C03F}.Debug|Any CPU.Build.0 = Debug|Any CPU
172+
{BBE55E49-F4CA-4EBD-C093-F8935A86C03F}.Release|Any CPU.ActiveCfg = Release|Any CPU
173+
{BBE55E49-F4CA-4EBD-C093-F8935A86C03F}.Release|Any CPU.Build.0 = Release|Any CPU
174+
{F34B21B1-A3FC-5284-DBB8-1188EAA04B83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
175+
{F34B21B1-A3FC-5284-DBB8-1188EAA04B83}.Debug|Any CPU.Build.0 = Debug|Any CPU
176+
{F34B21B1-A3FC-5284-DBB8-1188EAA04B83}.Release|Any CPU.ActiveCfg = Release|Any CPU
177+
{F34B21B1-A3FC-5284-DBB8-1188EAA04B83}.Release|Any CPU.Build.0 = Release|Any CPU
178+
{6ED66F0E-C7FA-3F0E-38C8-D576D48C8A58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
179+
{6ED66F0E-C7FA-3F0E-38C8-D576D48C8A58}.Debug|Any CPU.Build.0 = Debug|Any CPU
180+
{6ED66F0E-C7FA-3F0E-38C8-D576D48C8A58}.Release|Any CPU.ActiveCfg = Release|Any CPU
181+
{6ED66F0E-C7FA-3F0E-38C8-D576D48C8A58}.Release|Any CPU.Build.0 = Release|Any CPU
164182
EndGlobalSection
165183
GlobalSection(SolutionProperties) = preSolution
166184
HideSolutionNode = FALSE

sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ public static partial class ModelReaderWriter
234234
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) where T : System.ClientModel.Primitives.IPersistableModel<T> { throw null; }
235235
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions options, System.ClientModel.Primitives.ModelReaderWriterContext context) { throw null; }
236236
}
237+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true)]
238+
public partial class ModelReaderWriterBuildableAttribute : System.Attribute
239+
{
240+
public ModelReaderWriterBuildableAttribute(System.Type type) { }
241+
}
237242
public abstract partial class ModelReaderWriterContext
238243
{
239244
protected ModelReaderWriterContext() { }
@@ -252,13 +257,11 @@ public abstract partial class ModelReaderWriterTypeBuilder
252257
{
253258
protected ModelReaderWriterTypeBuilder() { }
254259
protected abstract System.Type BuilderType { get; }
255-
protected virtual bool IsCollection { get { throw null; } }
256260
protected virtual System.Type? ItemType { get { throw null; } }
257261
protected virtual void AddItem(object collection, object? item) { }
258262
protected virtual void AddKeyValuePair(object collection, string key, object? item) { }
259263
protected abstract object CreateInstance();
260-
public object CreateObject() { throw null; }
261-
protected internal virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
264+
protected virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
262265
protected virtual object ToCollection(object builder) { throw null; }
263266
}
264267
public abstract partial class OperationResult

sdk/core/System.ClientModel/api/System.ClientModel.net8.0.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ public static partial class ModelReaderWriter
234234
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) where T : System.ClientModel.Primitives.IPersistableModel<T> { throw null; }
235235
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions options, System.ClientModel.Primitives.ModelReaderWriterContext context) { throw null; }
236236
}
237+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true)]
238+
public partial class ModelReaderWriterBuildableAttribute : System.Attribute
239+
{
240+
public ModelReaderWriterBuildableAttribute(System.Type type) { }
241+
}
237242
public abstract partial class ModelReaderWriterContext
238243
{
239244
protected ModelReaderWriterContext() { }
@@ -252,13 +257,11 @@ public abstract partial class ModelReaderWriterTypeBuilder
252257
{
253258
protected ModelReaderWriterTypeBuilder() { }
254259
protected abstract System.Type BuilderType { get; }
255-
protected virtual bool IsCollection { get { throw null; } }
256260
protected virtual System.Type? ItemType { get { throw null; } }
257261
protected virtual void AddItem(object collection, object? item) { }
258262
protected virtual void AddKeyValuePair(object collection, string key, object? item) { }
259263
protected abstract object CreateInstance();
260-
public object CreateObject() { throw null; }
261-
protected internal virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
264+
protected virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
262265
protected virtual object ToCollection(object builder) { throw null; }
263266
}
264267
public abstract partial class OperationResult

sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ public static partial class ModelReaderWriter
234234
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions? options = null) where T : System.ClientModel.Primitives.IPersistableModel<T> { throw null; }
235235
public static System.BinaryData Write<T>(T model, System.ClientModel.Primitives.ModelReaderWriterOptions options, System.ClientModel.Primitives.ModelReaderWriterContext context) { throw null; }
236236
}
237+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true)]
238+
public partial class ModelReaderWriterBuildableAttribute : System.Attribute
239+
{
240+
public ModelReaderWriterBuildableAttribute(System.Type type) { }
241+
}
237242
public abstract partial class ModelReaderWriterContext
238243
{
239244
protected ModelReaderWriterContext() { }
@@ -252,13 +257,11 @@ public abstract partial class ModelReaderWriterTypeBuilder
252257
{
253258
protected ModelReaderWriterTypeBuilder() { }
254259
protected abstract System.Type BuilderType { get; }
255-
protected virtual bool IsCollection { get { throw null; } }
256260
protected virtual System.Type? ItemType { get { throw null; } }
257261
protected virtual void AddItem(object collection, object? item) { }
258262
protected virtual void AddKeyValuePair(object collection, string key, object? item) { }
259263
protected abstract object CreateInstance();
260-
public object CreateObject() { throw null; }
261-
protected internal virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
264+
protected virtual System.Collections.IEnumerable? GetItems(object obj) { throw null; }
262265
protected virtual object ToCollection(object builder) { throw null; }
263266
}
264267
public abstract partial class OperationResult
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
; Shipped analyzer releases
2+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Unshipped analyzer release
2+
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
--------|----------|----------|-------
7+
SCM0001 | ContextGenerator | Error | DiagnosticDescriptors
8+
SCM0002 | ContextGenerator | Error | DiagnosticDescriptors
9+
SCM0003 | ContextGenerator | Warning | DiagnosticDescriptors
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace System.ClientModel.SourceGeneration;
5+
6+
internal static class HashHelpers
7+
{
8+
public static int Combine(int h1, int h2)
9+
{
10+
// RyuJIT optimizes this to use the ROL instruction
11+
// Related GitHub pull request: https://github.com/dotnet/coreclr/pull/1830
12+
uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
13+
return ((int)rol5 + h1) ^ h2;
14+
}
15+
}

0 commit comments

Comments
 (0)