From 2872d2ea1d6287043e5c476c0a872d201e371dc9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 18 Sep 2011 15:53:29 +0200 Subject: [PATCH] fix #264: add UnresolvableDependencyPropertyDescriptor and UnresolvableType to represent types from assemblies that cannot be loaded --- ILSpy.BamlDecompiler/CecilType.cs | 6 ++-- ILSpy.BamlDecompiler/CecilTypeResolver.cs | 15 ++++++--- .../IDependencyPropertyDescriptor.cs | 9 ++++++ .../IType.cs | 32 +++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/ILSpy.BamlDecompiler/CecilType.cs b/ILSpy.BamlDecompiler/CecilType.cs index d41cac4c9..ab1f772c0 100644 --- a/ILSpy.BamlDecompiler/CecilType.cs +++ b/ILSpy.BamlDecompiler/CecilType.cs @@ -32,11 +32,11 @@ namespace ILSpy.BamlDecompiler if (type == null) throw new ArgumentNullException("type"); if (!(type is CecilType)) - throw new ArgumentException("type has to be a CecilType"); + return false; CecilType ct = (CecilType)type; - var t = ct.type; + var t = this.type; while (t != null) { if (t == ct.type) @@ -60,7 +60,7 @@ namespace ILSpy.BamlDecompiler if (type == null) throw new ArgumentNullException("type"); if (!(type is CecilType)) - throw new ArgumentException("type has to be a CecilType"); + return false; return this.type == ((CecilType)type).type; } diff --git a/ILSpy.BamlDecompiler/CecilTypeResolver.cs b/ILSpy.BamlDecompiler/CecilTypeResolver.cs index 8d57fa705..4008f3430 100644 --- a/ILSpy.BamlDecompiler/CecilTypeResolver.cs +++ b/ILSpy.BamlDecompiler/CecilTypeResolver.cs @@ -56,7 +56,7 @@ namespace ILSpy.BamlDecompiler if (type == null) { var otherAssembly = resolver.Resolve(assemblyName); if (otherAssembly == null) - throw new Exception("could not resolve '" + assemblyName + "'!"); + return new UnresolvableType(name); type = otherAssembly.MainModule.GetType(fullName.Replace('+', '/')); if (type == null) { @@ -65,7 +65,7 @@ namespace ILSpy.BamlDecompiler } if (type == null) - throw new Exception("could not resolve '" + name + "'!"); + return new UnresolvableType(name); return new CecilType(type); } @@ -83,10 +83,15 @@ namespace ILSpy.BamlDecompiler public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType) { - if (!(ownerType is CecilType)) - throw new ArgumentException(); + if (ownerType == null) + throw new ArgumentNullException("ownerType"); - return new CecilDependencyPropertyDescriptor(name, ((CecilType)ownerType).type); + if (ownerType is CecilType) + return new CecilDependencyPropertyDescriptor(name, ((CecilType)ownerType).type); + if (ownerType is UnresolvableType) + return new UnresolvableDependencyPropertyDescriptor(); + + throw new ArgumentException("Invalid IType: " + ownerType.GetType()); } public string RuntimeVersion { diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs index 0005efa52..516469cc6 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs @@ -11,4 +11,13 @@ namespace Ricciolo.StylesExplorer.MarkupReflection { bool IsAttached { get; } } + + public class UnresolvableDependencyPropertyDescriptor : IDependencyPropertyDescriptor + { + public bool IsAttached { + get { + return false; + } + } + } } diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs index b420bf480..d4efbc0a7 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs @@ -17,4 +17,36 @@ namespace Ricciolo.StylesExplorer.MarkupReflection bool IsSubclassOf(IType type); bool Equals(IType type); } + + public class UnresolvableType : IType + { + string assemblyQualifiedName; + + public UnresolvableType(string assemblyQualifiedName) + { + this.assemblyQualifiedName = assemblyQualifiedName; + } + + public IType BaseType { + get { + return null; + } + } + + public string AssemblyQualifiedName { + get { + return assemblyQualifiedName; + } + } + + public bool IsSubclassOf(IType type) + { + return Equals(type); + } + + public bool Equals(IType type) + { + return type is UnresolvableType && type.AssemblyQualifiedName == AssemblyQualifiedName; + } + } }