Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Shared/RoslynUtils/WellKnownTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static WellKnownTypes GetOrCreate(Compilation compilation) =>

private readonly INamedTypeSymbol?[] _lazyWellKnownTypes;
private readonly Compilation _compilation;
private readonly INamedTypeSymbol _missingTypeSymbol;

static WellKnownTypes()
{
Expand Down Expand Up @@ -51,6 +52,7 @@ private WellKnownTypes(Compilation compilation)
{
_lazyWellKnownTypes = new INamedTypeSymbol?[WellKnownTypeData.WellKnownTypeNames.Length];
_compilation = compilation;
_missingTypeSymbol = compilation.GetTypeByMetadataName(typeof(MissingType).FullName!)!;
}

public INamedTypeSymbol Get(SpecialType type)
Expand All @@ -74,11 +76,7 @@ public INamedTypeSymbol Get(WellKnownTypeData.WellKnownType type)

private INamedTypeSymbol GetAndCache(int index)
{
var result = GetTypeByMetadataNameInTargetAssembly(WellKnownTypeData.WellKnownTypeNames[index]);
if (result == null)
{
throw new InvalidOperationException($"Failed to resolve well-known type '{WellKnownTypeData.WellKnownTypeNames[index]}'.");
}
var result = GetTypeByMetadataNameInTargetAssembly(WellKnownTypeData.WellKnownTypeNames[index]) ?? _missingTypeSymbol;
Interlocked.CompareExchange(ref _lazyWellKnownTypes[index], result, null);

// GetTypeByMetadataName should always return the same instance for a name.
Expand Down Expand Up @@ -159,4 +157,6 @@ public static bool Implements(ITypeSymbol? type, ITypeSymbol interfaceType)
}
return false;
}

internal class MissingType { }
}
13 changes: 13 additions & 0 deletions src/Validation/src/Microsoft.Extensions.Validation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
<EnableDefaultItems>true</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Validation\gen\Microsoft.Extensions.Validation.ValidationsGenerator.csproj" Pack="false">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<!-- Package the generator in the analyzer directory of the nuget package -->
<None Include="$(OutputPath)\$(AssemblyName).ValidationsGenerator.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<Reference Include="Microsoft.Extensions.Options" />
Expand Down
Loading