Repository navigation
Expand file tree
/
Copy pathModifiedType.cs
More file actions
113 lines (98 loc) · 2.69 KB
/
Copy pathModifiedType.cs
File metadata and controls
113 lines (98 loc) · 2.69 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
/*
* Created by SharpDevelop.
* User: Illidan
* Date: 21.12.2012
* Time: 22:08
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using IllidanS4.SharpUtils.Reflection.Emit;
using IllidanS4.SharpUtils.Reflection.TypeSupport;
namespace IllidanS4.SharpUtils.Reflection
{
/// <summary>
/// Represents a type with custom modifiers.
/// </summary>
public class ModifiedType : TypeAppendConstruct
{
public TypeModifierCollection Modifiers{get; private set;}
public override CorElementType CorElementType{
get{
return ElementType.GetCorElementType();
}
}
private ModifiedType(Type baseType) : base(baseType, baseType.UnderlyingSystemType)
{
if(baseType == null) throw new ArgumentNullException("baseType");
}
public ModifiedType(Type baseType, params TypeModifier[] modifiers) : this(baseType, (IList<TypeModifier>)modifiers)
{
}
public ModifiedType(Type baseType, IList<TypeModifier> modifiers) : this(baseType)
{
if(modifiers == null)
{
Modifiers = TypeModifierCollection.Empty;
}else{
Modifiers = new TypeModifierCollection(modifiers.ToArray());
}
}
public ModifiedType(Type baseType, TypeModifierCollection modifiers) : this(baseType)
{
Modifiers = modifiers;
}
protected override string Append(string name)
{
return name+" "+String.Join(" ", Modifiers.Select(m => m.ToString()));
}
public override bool Equals(Type o)
{
if(!UnderlyingSystemType.Equals(o))return false;
ModifiedType modt = o as ModifiedType;
if(modt == null)
return Modifiers.Count == 0;
foreach(CustomTypeModifier modifier in Modifiers)
{
if(!modt.Modifiers.HasModifier(modifier))return false;
}
return true;
}
public override bool Equals(object o)
{
return Equals(o as Type);
}
public static bool operator ==(ModifiedType a, ModifiedType b)
{
if(Object.ReferenceEquals(a, b)) return true;
else if(Object.ReferenceEquals(a, null)) return false;
else return a.Equals(b);
}
public static bool operator !=(ModifiedType a, ModifiedType b)
{
return !(a == b);
}
public override int GetHashCode()
{
int hashCode = UnderlyingSystemType.GetHashCode();
unchecked{
foreach(CustomTypeModifier mod in Modifiers)
{
hashCode *= 17;
if(mod != null) hashCode += mod.GetHashCode();
}
}
return hashCode;
}
protected override void AddSignature(SignatureHelper signature)
{
signature.AddElement(Modifiers);
signature.AddArgumentSignature(ElementType);
}
}
}