File: TrimAnalysis\GenericParameterValue.cs
Web Access
Project: src\src\tools\illink\src\ILLink.RoslynAnalyzer\ILLink.RoslynAnalyzer.csproj (ILLink.RoslynAnalyzer)
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ILLink.RoslynAnalyzer;
using ILLink.Shared.DataFlow;
using Microsoft.CodeAnalysis;
 
namespace ILLink.Shared.TrimAnalysis
{
	/// <summary>
	/// This is a System.Type value which represents generic parameter (basically result of typeof(T))
	/// Its actual type is unknown, but it can have annotations.
	/// </summary>
	internal partial record GenericParameterValue
	{
		public GenericParameterValue (ITypeParameterSymbol typeParameterSymbol, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
		{
			GenericParameter = new (typeParameterSymbol);
			DynamicallyAccessedMemberTypes = dynamicallyAccessedMemberTypes;
		}
 
		public GenericParameterValue (ITypeParameterSymbol typeParameterSymbol)
			: this (typeParameterSymbol, typeParameterSymbol.GetDynamicallyAccessedMemberTypes ())
		{
		}
 
		public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; }
 
		public override IEnumerable<string> GetDiagnosticArgumentsForAnnotationMismatch ()
			=> new string[] { GenericParameter.TypeParameterSymbol.Name, GenericParameter.TypeParameterSymbol.ContainingSymbol.GetDisplayName () };
 
		public override SingleValue DeepCopy () => this; // This value is immutable
 
		public override string ToString ()
			=> this.ValueToString (GenericParameter.TypeParameterSymbol, DynamicallyAccessedMemberTypes);
	}
}