PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Mono.Cecil/MemberReference.cs

http://github.com/jbevain/cecil
C# | 107 lines | 74 code | 24 blank | 9 comment | 11 complexity | 56d1cfe534fe0eca7b11b94ab6b7f879 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
 13namespace Mono.Cecil {
 14
 15	public abstract class MemberReference : IMetadataTokenProvider {
 16
 17		string name;
 18		TypeReference declaring_type;
 19
 20		internal MetadataToken token;
 21		internal object projection;
 22
 23		public virtual string Name {
 24			get { return name; }
 25			set {
 26				if (IsWindowsRuntimeProjection && value != name)
 27					throw new InvalidOperationException ();
 28
 29				name = value;
 30			}
 31		}
 32
 33		public abstract string FullName {
 34			get;
 35		}
 36
 37		public virtual TypeReference DeclaringType {
 38			get { return declaring_type; }
 39			set { declaring_type = value; }
 40		}
 41
 42		public MetadataToken MetadataToken {
 43			get { return token; }
 44			set { token = value; }
 45		}
 46
 47		public bool IsWindowsRuntimeProjection {
 48			get { return projection != null; }
 49		}
 50
 51		internal MemberReferenceProjection WindowsRuntimeProjection {
 52			get { return (MemberReferenceProjection) projection; }
 53			set { projection = value; }
 54		}
 55
 56		internal bool HasImage {
 57			get {
 58				var module = Module;
 59				if (module == null)
 60					return false;
 61
 62				return module.HasImage;
 63			}
 64		}
 65
 66		public virtual ModuleDefinition Module {
 67			get { return declaring_type != null ? declaring_type.Module : null; }
 68		}
 69
 70		public virtual bool IsDefinition {
 71			get { return false; }
 72		}
 73
 74		public virtual bool ContainsGenericParameter {
 75			get { return declaring_type != null && declaring_type.ContainsGenericParameter; }
 76		}
 77
 78		internal MemberReference ()
 79		{
 80		}
 81
 82		internal MemberReference (string name)
 83		{
 84			this.name = name ?? string.Empty;
 85		}
 86
 87		internal string MemberFullName ()
 88		{
 89			if (declaring_type == null)
 90				return name;
 91
 92			return declaring_type.FullName + "::" + name;
 93		}
 94
 95		public IMemberDefinition Resolve ()
 96		{
 97			return ResolveDefinition ();
 98		}
 99
100		protected abstract IMemberDefinition ResolveDefinition ();
101
102		public override string ToString ()
103		{
104			return FullName;
105		}
106	}
107}