mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team |
|
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) |
|
|
|
using System; |
|
using System.Linq; |
|
using ICSharpCode.Decompiler.TypeSystem; |
|
using Mono.Cecil; |
|
using Ricciolo.StylesExplorer.MarkupReflection; |
|
|
|
namespace ILSpy.BamlDecompiler |
|
{ |
|
public class NRType : IDotNetType |
|
{ |
|
readonly ITypeDefinition type; |
|
|
|
public ITypeDefinition Type => type; |
|
|
|
public NRType(ITypeDefinition type) |
|
{ |
|
this.type = type ?? throw new ArgumentNullException(nameof(type)); |
|
} |
|
|
|
public string AssemblyQualifiedName { |
|
get { |
|
return type.FullName + |
|
", " + type.ParentAssembly.FullAssemblyName; |
|
} |
|
} |
|
|
|
public bool IsSubclassOf(IDotNetType type) |
|
{ |
|
if (type == null) |
|
throw new ArgumentNullException(nameof(type)); |
|
if (!(type is NRType baseType)) |
|
return false; |
|
|
|
return this.type.GetAllBaseTypeDefinitions().Any(t => t.Equals(baseType.type)); |
|
} |
|
|
|
public bool Equals(IDotNetType type) |
|
{ |
|
if (type == null) |
|
throw new ArgumentNullException("type"); |
|
if (!(type is NRType)) |
|
return false; |
|
|
|
return this.type.Equals(((NRType)type).type); |
|
} |
|
|
|
public override string ToString() |
|
{ |
|
return string.Format("[CecilType Type={0}]", type); |
|
} |
|
|
|
public IDotNetType BaseType { |
|
get { |
|
var t = type.DirectBaseTypes.First(); |
|
var td = t.GetDefinition(); |
|
if (td == null) |
|
throw new Exception($"Could not resolve '{t.FullName}'!"); |
|
|
|
return new NRType(td); |
|
} |
|
} |
|
} |
|
}
|
|
|