~ubuntu-branches/ubuntu/wily/monodevelop/wily

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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// TypeReference.cs
//
// Author:
//   Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

namespace Mono.Cecil {

	public class TypeReference : MemberReference, IGenericParameterProvider, ICustomAttributeProvider {

		string m_namespace;
		bool m_fullNameDiscarded;
		string m_fullName;
		protected bool m_isValueType;
		IMetadataScope m_scope;
		ModuleDefinition m_module;

		CustomAttributeCollection m_customAttrs;
		GenericParameterCollection m_genparams;

		public override string Name {
			get { return base.Name; }
			set {
				base.Name = value;
				m_fullNameDiscarded = true;
			}
		}

		public virtual string Namespace {
			get { return m_namespace; }
			set {
				m_namespace = value;
				m_fullNameDiscarded = true;
			}
		}

		public virtual bool IsValueType {
			get { return m_isValueType; }
			set { m_isValueType = value; }
		}

		public virtual ModuleDefinition Module {
			get { return m_module; }
			set { m_module = value; }
		}

		public bool HasCustomAttributes {
			get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
		}

		public CustomAttributeCollection CustomAttributes {
			get {
				if (m_customAttrs == null)
					m_customAttrs = new CustomAttributeCollection (this);

				return m_customAttrs;
			}
		}

		public bool HasGenericParameters {
			get { return (m_genparams == null) ? false : (m_genparams.Count > 0); }
		}

		public GenericParameterCollection GenericParameters {
			get {
				if (m_genparams == null)
					m_genparams = new GenericParameterCollection (this);
				return m_genparams;
			}
		}

		public virtual IMetadataScope Scope {
			get {
				if (this.DeclaringType != null)
					return this.DeclaringType.Scope;

				return m_scope;
			}
		}

		public bool IsNested {
			get { return this.DeclaringType != null; }
		}

		public virtual string FullName {
			get {
				if (m_fullName != null && !m_fullNameDiscarded)
					return m_fullName;

				if (this.IsNested)
					return string.Concat (this.DeclaringType.FullName, "/", this.Name);

				if (m_namespace == null || m_namespace.Length == 0)
					return this.Name;

				m_fullName = string.Concat (m_namespace, ".", this.Name);
				m_fullNameDiscarded = false;
				return m_fullName;
			}
		}

		protected TypeReference (string name, string ns) : base (name)
		{
			m_namespace = ns;
			m_fullNameDiscarded = false;
		}

		internal TypeReference (string name, string ns, IMetadataScope scope) : this (name, ns)
		{
			m_scope = scope;
		}

		public TypeReference (string name, string ns, IMetadataScope scope, bool valueType) :
			this (name, ns, scope)
		{
			m_isValueType = valueType;
		}

		public virtual TypeDefinition Resolve ()
		{
			ModuleDefinition module = Module;
			if (module == null)
				return null;

			return module.Resolver.Resolve (this);
		}

		public virtual TypeReference GetOriginalType ()
		{
			return this;
		}

		internal void AttachToScope (IMetadataScope scope)
		{
			m_scope = scope;
		}

		public override void Accept (IReflectionVisitor visitor)
		{
			visitor.VisitTypeReference (this);
		}

		public override string ToString ()
		{
			return this.FullName;
		}
	}
}