5 // Jb Evain (jbevain@gmail.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace Mono.Cecil {
31 internal class TypeReference : MemberReference, IGenericParameterProvider, ICustomAttributeProvider {
34 bool m_fullNameDiscarded;
36 protected bool m_isValueType;
37 IMetadataScope m_scope;
38 ModuleDefinition m_module;
40 CustomAttributeCollection m_customAttrs;
41 GenericParameterCollection m_genparams;
43 public override string Name {
44 get { return base.Name; }
47 m_fullNameDiscarded = true;
51 public virtual string Namespace {
52 get { return m_namespace; }
55 m_fullNameDiscarded = true;
59 public virtual bool IsValueType {
60 get { return m_isValueType; }
61 set { m_isValueType = value; }
64 public virtual ModuleDefinition Module {
65 get { return m_module; }
66 set { m_module = value; }
69 public bool HasCustomAttributes {
70 get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
73 public CustomAttributeCollection CustomAttributes {
75 if (m_customAttrs == null)
76 m_customAttrs = new CustomAttributeCollection (this);
82 public bool HasGenericParameters {
83 get { return (m_genparams == null) ? false : (m_genparams.Count > 0); }
86 public GenericParameterCollection GenericParameters {
88 if (m_genparams == null)
89 m_genparams = new GenericParameterCollection (this);
94 public virtual IMetadataScope Scope {
96 if (this.DeclaringType != null)
97 return this.DeclaringType.Scope;
103 public bool IsNested {
104 get { return this.DeclaringType != null; }
107 public virtual string FullName {
109 if (m_fullName != null && !m_fullNameDiscarded)
113 return string.Concat (this.DeclaringType.FullName, "/", this.Name);
115 if (m_namespace == null || m_namespace.Length == 0)
118 m_fullName = string.Concat (m_namespace, ".", this.Name);
119 m_fullNameDiscarded = false;
124 protected TypeReference (string name, string ns) : base (name)
127 m_fullNameDiscarded = false;
130 internal TypeReference (string name, string ns, IMetadataScope scope) : this (name, ns)
135 public TypeReference (string name, string ns, IMetadataScope scope, bool valueType) :
136 this (name, ns, scope)
138 m_isValueType = valueType;
141 public virtual TypeDefinition Resolve ()
143 ModuleDefinition module = Module;
147 return module.Resolver.Resolve (this);
150 public virtual TypeReference GetOriginalType ()
155 internal void AttachToScope (IMetadataScope scope)
160 public override void Accept (IReflectionVisitor visitor)
162 visitor.VisitTypeReference (this);
165 public override string ToString ()
167 return this.FullName;