-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathGenericParameter.cs
More file actions
154 lines (132 loc) · 5.08 KB
/
GenericParameter.cs
File metadata and controls
154 lines (132 loc) · 5.08 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain.Dependencies;
using JetBrains.Annotations;
namespace ArchUnitNET.Domain
{
public class GenericParameter : IType
{
private readonly string _declarerFullName;
internal readonly IEnumerable<ITypeInstance<IType>> TypeInstanceConstraints;
public GenericParameter(
string declarerFullName,
string name,
GenericParameterVariance variance,
IEnumerable<ITypeInstance<IType>> typeConstraints,
bool hasReferenceTypeConstraint,
bool hasNotNullableValueTypeConstraint,
bool hasDefaultConstructorConstraint,
bool isCompilerGenerated,
bool declarerIsMethod
)
{
_declarerFullName = declarerFullName;
Name = name;
Variance = variance;
TypeInstanceConstraints = typeConstraints;
HasReferenceTypeConstraint = hasReferenceTypeConstraint;
HasNotNullableValueTypeConstraint = hasNotNullableValueTypeConstraint;
HasDefaultConstructorConstraint = hasDefaultConstructorConstraint;
IsCompilerGenerated = isCompilerGenerated;
DeclarerIsMethod = declarerIsMethod;
}
public IType DeclaringType { get; private set; }
[CanBeNull]
public IMember DeclaringMethod { get; private set; }
public bool DeclarerIsMethod { get; }
public GenericParameterVariance Variance { get; }
public IEnumerable<IType> TypeConstraints =>
TypeInstanceConstraints.Select(instance => instance.Type);
public bool HasReferenceTypeConstraint { get; }
public bool HasNotNullableValueTypeConstraint { get; }
public bool HasDefaultConstructorConstraint { get; }
public bool HasConstraints =>
HasReferenceTypeConstraint
|| HasNotNullableValueTypeConstraint
|| HasDefaultConstructorConstraint
|| TypeConstraints.Any();
public string Name { get; }
public string FullName => _declarerFullName + "+<" + Name + ">";
public string AssemblyQualifiedName =>
System.Reflection.Assembly.CreateQualifiedName(
DeclaringType.Assembly.FullName,
FullName
);
public bool IsCompilerGenerated { get; }
public IEnumerable<Attribute> Attributes =>
AttributeInstances.Select(instance => instance.Type);
public List<AttributeInstance> AttributeInstances { get; } = new List<AttributeInstance>();
public List<ITypeDependency> Dependencies { get; } = new List<ITypeDependency>();
public List<ITypeDependency> BackwardsDependencies { get; } = new List<ITypeDependency>();
public Visibility Visibility => Visibility.NotAccessible;
public bool IsGeneric => false;
public bool IsGenericParameter => true;
public List<GenericParameter> GenericParameters => new List<GenericParameter>();
public Namespace Namespace => DeclaringType?.Namespace;
public Assembly Assembly => DeclaringType?.Assembly;
public MemberList Members => new MemberList();
public IEnumerable<IType> ImplementedInterfaces => Enumerable.Empty<IType>();
public bool IsNested => true;
public bool IsStub => true;
internal void AssignDeclarer(IMember declaringMethod)
{
if (!declaringMethod.FullName.Equals(_declarerFullName))
{
throw new InvalidOperationException("Full name of declaring member doesn't match.");
}
DeclaringType = declaringMethod.DeclaringType;
DeclaringMethod = declaringMethod;
}
internal void AssignDeclarer(IType declaringType)
{
if (!declaringType.FullName.Equals(_declarerFullName))
{
throw new InvalidOperationException("Full name of declaring type doesn't match.");
}
DeclaringType = declaringType;
}
public bool Equals(GenericParameter other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Equals(FullName, other.FullName);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((GenericParameter)obj);
}
public override int GetHashCode()
{
return FullName.GetHashCode();
}
public override string ToString()
{
return FullName;
}
}
public enum GenericParameterVariance
{
NonVariant,
Covariant,
Contravariant,
}
}