-
Notifications
You must be signed in to change notification settings - Fork 87
/
FieldRef.cs
57 lines (45 loc) · 1.94 KB
/
FieldRef.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
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.VisualStudio.Composition.Reflection
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class FieldRef : MemberRef, IEquatable<FieldRef>
{
/// <summary>
/// Gets the string to display in the debugger watch window for this value.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay => $"{this.DeclaringType.FullName}.{this.Name}";
public FieldRef(TypeRef declaringType, TypeRef fieldTypeRef, int metadataToken, string name, bool isStatic)
: base(declaringType, metadataToken, isStatic)
{
Requires.NotNullOrEmpty(name, nameof(name));
this.Name = name;
this.FieldTypeRef = fieldTypeRef;
}
public FieldRef(FieldInfo field, Resolver resolver)
: base(field, resolver)
{
this.Name = field.Name;
this.FieldTypeRef = TypeRef.Get(field.FieldType, resolver);
}
public FieldInfo FieldInfo => (FieldInfo)this.MemberInfo;
public TypeRef FieldTypeRef { get; }
public override string Name { get; }
internal override void GetInputAssemblies(ISet<AssemblyName> assemblies) => this.DeclaringType?.GetInputAssemblies(assemblies);
protected override bool EqualsByTypeLocalMetadata(MemberRef other)
{
var otherField = (FieldRef)other;
return this.Name == otherField.Name;
}
public bool Equals(FieldRef fieldRef) => this.Equals((MemberRef)fieldRef);
public override int GetHashCode()
{
return this.DeclaringType.GetHashCode() + this.Name.GetHashCode();
}
protected override MemberInfo Resolve() => ResolverExtensions.Resolve(this);
}
}