PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/Mono.Cecil/Mono.Cecil/Modifiers.cs

http://github.com/icsharpcode/ILSpy
C# | 137 lines | 83 code | 27 blank | 27 comment | 6 complexity | ef9559449ce5215f80549ef2d94e1d35 MD5 | raw file
  1//
  2// Modifiers.cs
  3//
  4// Author:
  5//   Jb Evain (jbevain@gmail.com)
  6//
  7// Copyright (c) 2008 - 2011 Jb Evain
  8//
  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:
 16//
 17// The above copyright notice and this permission notice shall be
 18// included in all copies or substantial portions of the Software.
 19//
 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.
 27//
 28
 29using System;
 30
 31using MD = Mono.Cecil.Metadata;
 32
 33namespace Mono.Cecil {
 34
 35	public interface IModifierType {
 36		TypeReference ModifierType { get; }
 37		TypeReference ElementType { get; }
 38	}
 39
 40	public sealed class OptionalModifierType : TypeSpecification, IModifierType {
 41
 42		TypeReference modifier_type;
 43
 44		public TypeReference ModifierType {
 45			get { return modifier_type; }
 46			set { modifier_type = value; }
 47		}
 48
 49		public override string Name {
 50			get { return base.Name + Suffix; }
 51		}
 52
 53		public override string FullName {
 54			get { return base.FullName + Suffix; }
 55		}
 56
 57		string Suffix {
 58			get { return " modopt(" + modifier_type + ")"; }
 59		}
 60
 61		public override bool IsValueType {
 62			get { return false; }
 63			set { throw new InvalidOperationException (); }
 64		}
 65
 66		public override bool IsOptionalModifier {
 67			get { return true; }
 68		}
 69
 70		internal override bool ContainsGenericParameter {
 71			get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
 72		}
 73
 74		public OptionalModifierType (TypeReference modifierType, TypeReference type)
 75			: base (type)
 76		{
 77			Mixin.CheckModifier (modifierType, type);
 78			this.modifier_type = modifierType;
 79			this.etype = MD.ElementType.CModOpt;
 80		}
 81	}
 82
 83	public sealed class RequiredModifierType : TypeSpecification, IModifierType {
 84
 85		TypeReference modifier_type;
 86
 87		public TypeReference ModifierType {
 88			get { return modifier_type; }
 89			set { modifier_type = value; }
 90		}
 91
 92		public override string Name {
 93			get { return base.Name + Suffix; }
 94		}
 95
 96		public override string FullName {
 97			get { return base.FullName + Suffix; }
 98		}
 99
100		string Suffix {
101			get { return " modreq(" + modifier_type + ")"; }
102		}
103
104		public override bool IsValueType {
105			get { return false; }
106			set { throw new InvalidOperationException (); }
107		}
108
109		public override bool IsRequiredModifier {
110			get { return true; }
111		}
112
113		internal override bool ContainsGenericParameter {
114			get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
115		}
116
117		public RequiredModifierType (TypeReference modifierType, TypeReference type)
118			: base (type)
119		{
120			Mixin.CheckModifier (modifierType, type);
121			this.modifier_type = modifierType;
122			this.etype = MD.ElementType.CModReqD;
123		}
124
125	}
126
127	static partial class Mixin {
128
129		public static void CheckModifier (TypeReference modifierType, TypeReference type)
130		{
131			if (modifierType == null)
132				throw new ArgumentNullException ("modifierType");
133			if (type == null)
134				throw new ArgumentNullException ("type");
135		}
136	}
137}