PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Mono.Cecil/Modifiers.cs

http://github.com/jbevain/cecil
C# | 112 lines | 78 code | 25 blank | 9 comment | 6 complexity | 00e31b5a0b259fa08fb188194f023461 MD5 | raw file
  1//
  2// Author:
  3//   Jb Evain (jbevain@gmail.com)
  4//
  5// Copyright (c) 2008 - 2015 Jb Evain
  6// Copyright (c) 2008 - 2011 Novell, Inc.
  7//
  8// Licensed under the MIT/X11 license.
  9//
 10
 11using System;
 12
 13using MD = Mono.Cecil.Metadata;
 14
 15namespace Mono.Cecil {
 16
 17	public interface IModifierType {
 18		TypeReference ModifierType { get; }
 19		TypeReference ElementType { get; }
 20	}
 21
 22	public sealed class OptionalModifierType : TypeSpecification, IModifierType {
 23
 24		TypeReference modifier_type;
 25
 26		public TypeReference ModifierType {
 27			get { return modifier_type; }
 28			set { modifier_type = value; }
 29		}
 30
 31		public override string Name {
 32			get { return base.Name + Suffix; }
 33		}
 34
 35		public override string FullName {
 36			get { return base.FullName + Suffix; }
 37		}
 38
 39		string Suffix {
 40			get { return " modopt(" + modifier_type + ")"; }
 41		}
 42
 43		public override bool IsValueType {
 44			get { return false; }
 45			set { throw new InvalidOperationException (); }
 46		}
 47
 48		public override bool IsOptionalModifier {
 49			get { return true; }
 50		}
 51
 52		public override bool ContainsGenericParameter {
 53			get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
 54		}
 55
 56		public OptionalModifierType (TypeReference modifierType, TypeReference type)
 57			: base (type)
 58		{
 59			if (modifierType == null)
 60				throw new ArgumentNullException (Mixin.Argument.modifierType.ToString ());
 61			Mixin.CheckType (type);
 62			this.modifier_type = modifierType;
 63			this.etype = MD.ElementType.CModOpt;
 64		}
 65	}
 66
 67	public sealed class RequiredModifierType : TypeSpecification, IModifierType {
 68
 69		TypeReference modifier_type;
 70
 71		public TypeReference ModifierType {
 72			get { return modifier_type; }
 73			set { modifier_type = value; }
 74		}
 75
 76		public override string Name {
 77			get { return base.Name + Suffix; }
 78		}
 79
 80		public override string FullName {
 81			get { return base.FullName + Suffix; }
 82		}
 83
 84		string Suffix {
 85			get { return " modreq(" + modifier_type + ")"; }
 86		}
 87
 88		public override bool IsValueType {
 89			get { return false; }
 90			set { throw new InvalidOperationException (); }
 91		}
 92
 93		public override bool IsRequiredModifier {
 94			get { return true; }
 95		}
 96
 97		public override bool ContainsGenericParameter {
 98			get { return modifier_type.ContainsGenericParameter || base.ContainsGenericParameter; }
 99		}
100
101		public RequiredModifierType (TypeReference modifierType, TypeReference type)
102			: base (type)
103		{
104			if (modifierType == null)
105				throw new ArgumentNullException (Mixin.Argument.modifierType.ToString ());
106			Mixin.CheckType (type);
107			this.modifier_type = modifierType;
108			this.etype = MD.ElementType.CModReqD;
109		}
110
111	}
112}