5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2011 Jb Evain
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.
31
namespace Mono.Cecil {
33
public class ExportedType : IMetadataTokenProvider {
39
ModuleDefinition module;
41
ExportedType declaring_type;
42
internal MetadataToken token;
44
public string Namespace {
45
get { return @namespace; }
46
set { @namespace = value; }
54
public TypeAttributes Attributes {
55
get { return (TypeAttributes) attributes; }
56
set { attributes = (uint) value; }
59
public IMetadataScope Scope {
61
if (declaring_type != null)
62
return declaring_type.Scope;
68
public ExportedType DeclaringType {
69
get { return declaring_type; }
70
set { declaring_type = value; }
73
public MetadataToken MetadataToken {
75
set { token = value; }
78
public int Identifier {
79
get { return identifier; }
80
set { identifier = value; }
83
#region TypeAttributes
85
public bool IsNotPublic {
86
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic); }
87
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic, value); }
90
public bool IsPublic {
91
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public); }
92
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public, value); }
95
public bool IsNestedPublic {
96
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic); }
97
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic, value); }
100
public bool IsNestedPrivate {
101
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate); }
102
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate, value); }
105
public bool IsNestedFamily {
106
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily); }
107
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily, value); }
110
public bool IsNestedAssembly {
111
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly); }
112
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly, value); }
115
public bool IsNestedFamilyAndAssembly {
116
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem); }
117
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem, value); }
120
public bool IsNestedFamilyOrAssembly {
121
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem); }
122
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem, value); }
125
public bool IsAutoLayout {
126
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout); }
127
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout, value); }
130
public bool IsSequentialLayout {
131
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout); }
132
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout, value); }
135
public bool IsExplicitLayout {
136
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout); }
137
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout, value); }
140
public bool IsClass {
141
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class); }
142
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class, value); }
145
public bool IsInterface {
146
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface); }
147
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface, value); }
150
public bool IsAbstract {
151
get { return attributes.GetAttributes ((uint) TypeAttributes.Abstract); }
152
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Abstract, value); }
155
public bool IsSealed {
156
get { return attributes.GetAttributes ((uint) TypeAttributes.Sealed); }
157
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Sealed, value); }
160
public bool IsSpecialName {
161
get { return attributes.GetAttributes ((uint) TypeAttributes.SpecialName); }
162
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.SpecialName, value); }
165
public bool IsImport {
166
get { return attributes.GetAttributes ((uint) TypeAttributes.Import); }
167
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Import, value); }
170
public bool IsSerializable {
171
get { return attributes.GetAttributes ((uint) TypeAttributes.Serializable); }
172
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Serializable, value); }
175
public bool IsAnsiClass {
176
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass); }
177
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass, value); }
180
public bool IsUnicodeClass {
181
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass); }
182
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass, value); }
185
public bool IsAutoClass {
186
get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass); }
187
set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass, value); }
190
public bool IsBeforeFieldInit {
191
get { return attributes.GetAttributes ((uint) TypeAttributes.BeforeFieldInit); }
192
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.BeforeFieldInit, value); }
195
public bool IsRuntimeSpecialName {
196
get { return attributes.GetAttributes ((uint) TypeAttributes.RTSpecialName); }
197
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.RTSpecialName, value); }
200
public bool HasSecurity {
201
get { return attributes.GetAttributes ((uint) TypeAttributes.HasSecurity); }
202
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.HasSecurity, value); }
207
public bool IsForwarder {
208
get { return attributes.GetAttributes ((uint) TypeAttributes.Forwarder); }
209
set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Forwarder, value); }
212
public string FullName {
214
if (declaring_type != null)
215
return declaring_type.FullName + "/" + name;
217
if (string.IsNullOrEmpty (@namespace))
220
return @namespace + "." + name;
224
public ExportedType (string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
226
this.@namespace = @namespace;
229
this.module = module;
232
public override string ToString ()
237
public TypeDefinition Resolve ()
239
return module.Resolve (CreateReference ());
242
internal TypeReference CreateReference ()
244
return new TypeReference (@namespace, name, module, scope) {
245
DeclaringType = declaring_type != null ? declaring_type.CreateReference () : null,