/
TypeInfo.cs
67 lines (57 loc) · 2.71 KB
/
TypeInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
public readonly struct TypeInfo : IEquatable<TypeInfo>
{
internal static readonly TypeInfo None = new TypeInfo(type: null, convertedType: null, nullability: default, convertedNullability: default);
/// <summary>
/// The type of the expression represented by the syntax node. For expressions that do not
/// have a type, null is returned. If the type could not be determined due to an error, then
/// an IErrorTypeSymbol is returned.
/// </summary>
public ITypeSymbol Type { get; }
/// <summary>
/// The top-level nullability information of the expression represented by the syntax node.
/// </summary>
public NullabilityInfo Nullability { get; }
/// <summary>
/// The type of the expression after it has undergone an implicit conversion. If the type
/// did not undergo an implicit conversion, returns the same as Type.
/// </summary>
public ITypeSymbol ConvertedType { get; }
/// <summary>
/// The top-level nullability of the expression after it has undergone an implicit conversion.
/// For most expressions, this will be the same as the type. It can change in situations such
/// as implicit user-defined conversions that have a nullable return type.
/// </summary>
public NullabilityInfo ConvertedNullability { get; }
internal TypeInfo(ITypeSymbol type, ITypeSymbol convertedType, NullabilityInfo nullability, NullabilityInfo convertedNullability)
: this()
{
this.Type = type;
this.Nullability = nullability;
this.ConvertedType = convertedType;
this.ConvertedNullability = convertedNullability;
}
public bool Equals(TypeInfo other)
{
return object.Equals(this.Type, other.Type)
&& object.Equals(this.ConvertedType, other.ConvertedType)
&& this.Nullability.Equals(other.Nullability)
&& this.ConvertedNullability.Equals(other.ConvertedNullability);
}
public override bool Equals(object obj)
{
return obj is TypeInfo && this.Equals((TypeInfo)obj);
}
public override int GetHashCode()
{
return Hash.Combine(this.ConvertedType,
Hash.Combine(this.Type,
Hash.Combine(this.Nullability.GetHashCode(),
this.ConvertedNullability.GetHashCode())));
}
}
}