mirror of https://github.com/icsharpcode/ILSpy.git
5 changed files with 160 additions and 1 deletions
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// 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.ILSpy; |
||||
using Mono.Cecil; |
||||
using Ricciolo.StylesExplorer.MarkupReflection; |
||||
|
||||
namespace ILSpy.BamlDecompiler |
||||
{ |
||||
public class CecilDependencyPropertyDescriptor : IDependencyPropertyDescriptor |
||||
{ |
||||
string member; |
||||
TypeDefinition type; |
||||
|
||||
public CecilDependencyPropertyDescriptor(string member, TypeDefinition type) |
||||
{ |
||||
this.member = member; |
||||
this.type = type; |
||||
} |
||||
|
||||
public bool IsAttached { |
||||
get { |
||||
return type.Methods.Any(m => m.Name == "Get" + member); |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[CecilDependencyPropertyDescriptor Member={0}, Type={1}]", member, type); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
// 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.ILSpy; |
||||
using Mono.Cecil; |
||||
using Ricciolo.StylesExplorer.MarkupReflection; |
||||
|
||||
namespace ILSpy.BamlDecompiler |
||||
{ |
||||
public class CecilType : IType |
||||
{ |
||||
internal readonly TypeDefinition type; |
||||
|
||||
public CecilType(TypeDefinition type) |
||||
{ |
||||
this.type = type; |
||||
} |
||||
|
||||
public string AssemblyQualifiedName { |
||||
get { |
||||
return type.FullName + |
||||
", " + type.Module.Assembly.FullName; |
||||
} |
||||
} |
||||
|
||||
public bool IsSubclassOf(IType type) |
||||
{ |
||||
if (type == null) |
||||
throw new ArgumentNullException("type"); |
||||
if (!(type is CecilType)) |
||||
throw new ArgumentException("type has to be a CecilType"); |
||||
|
||||
CecilType ct = (CecilType)type; |
||||
|
||||
var t = ct.type; |
||||
|
||||
while (t != null) { |
||||
if (t == ct.type) |
||||
return true; |
||||
foreach (var @interface in t.Interfaces) { |
||||
var resolved = @interface.Resolve(); |
||||
if (resolved == ct.type) |
||||
return true; |
||||
} |
||||
if (t.BaseType == null) |
||||
break; |
||||
|
||||
t = t.BaseType.Resolve(); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public bool Equals(IType type) |
||||
{ |
||||
if (type == null) |
||||
throw new ArgumentNullException("type"); |
||||
if (!(type is CecilType)) |
||||
throw new ArgumentException("type has to be a CecilType"); |
||||
|
||||
return this.type == ((CecilType)type).type; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[CecilType Type={0}]", type); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// 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.ILSpy; |
||||
using Mono.Cecil; |
||||
using Ricciolo.StylesExplorer.MarkupReflection; |
||||
|
||||
namespace ILSpy.BamlDecompiler |
||||
{ |
||||
/// <summary>
|
||||
/// Description of CecilTypeResolver.
|
||||
/// </summary>
|
||||
public class CecilTypeResolver : ITypeResolver |
||||
{ |
||||
LoadedAssembly assembly; |
||||
|
||||
public CecilTypeResolver(LoadedAssembly assembly) |
||||
{ |
||||
this.assembly = assembly; |
||||
} |
||||
|
||||
public IType GetTypeByAssemblyQualifiedName(string name) |
||||
{ |
||||
int comma = name.IndexOf(','); |
||||
|
||||
if (comma == -1) |
||||
throw new ArgumentException("invalid name"); |
||||
|
||||
string fullName = name.Substring(0, comma); |
||||
string assemblyName = name.Substring(comma + 1).Trim(); |
||||
|
||||
var type = assembly.AssemblyDefinition.MainModule.GetType(fullName); |
||||
if (type == null) { |
||||
var otherAssembly = assembly.LookupReferencedAssembly(assemblyName); |
||||
type = otherAssembly.AssemblyDefinition.MainModule.GetType(fullName); |
||||
} |
||||
|
||||
return new CecilType(type); |
||||
} |
||||
|
||||
public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType) |
||||
{ |
||||
if (!(ownerType is CecilType)) |
||||
throw new ArgumentException(); |
||||
|
||||
return new CecilDependencyPropertyDescriptor(name, ((CecilType)ownerType).type); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue