-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create shared WellKnownTypes enum (dotnet/linker#2692)
Commit migrated from dotnet/linker@1d77412
- Loading branch information
1 parent
bd9f220
commit 40f5127
Showing
9 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/WellKnownTypeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace ILLink.Shared.TypeSystemProxy | ||
{ | ||
public static partial class WellKnownTypeExtensions | ||
{ | ||
public static bool TryGetSpecialType (this WellKnownType wellKnownType, [NotNullWhen (true)] out SpecialType? specialType) | ||
{ | ||
specialType = wellKnownType switch { | ||
WellKnownType.System_String => SpecialType.System_String, | ||
WellKnownType.System_Nullable_T => SpecialType.System_Nullable_T, | ||
WellKnownType.System_Array => SpecialType.System_Array, | ||
WellKnownType.System_Object => SpecialType.System_Object, | ||
_ => null, | ||
}; | ||
return specialType is not null; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/tools/illink/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace ILLink.Shared.TypeSystemProxy | ||
{ | ||
public enum WellKnownType | ||
{ | ||
System_String, | ||
System_Nullable_T, | ||
System_Type, | ||
System_Reflection_IReflect, | ||
System_Array, | ||
System_Object, | ||
System_Attribute | ||
} | ||
|
||
public static partial class WellKnownTypeExtensions | ||
{ | ||
public static (string Namespace, string Name) GetNamespaceAndName (this WellKnownType type) | ||
{ | ||
return type switch { | ||
WellKnownType.System_String => ("System", "String"), | ||
WellKnownType.System_Nullable_T => ("System", "Nullable`1"), | ||
WellKnownType.System_Type => ("System", "Type"), | ||
WellKnownType.System_Reflection_IReflect => ("System.Reflection", "IReflect"), | ||
WellKnownType.System_Array => ("System", "Array"), | ||
WellKnownType.System_Object => ("System", "Object"), | ||
WellKnownType.System_Attribute => ("System", "Attribute"), | ||
_ => throw new ArgumentException ($"{nameof (type)} is not a well-known type."), | ||
}; | ||
} | ||
public static string GetNamespace (this WellKnownType type) => GetNamespaceAndName (type).Namespace; | ||
public static string GetName (this WellKnownType type) => GetNamespaceAndName (type).Name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters