Browse Source

implemented using base type as root node in decompiled BAML

pull/234/merge
Siegfried Pammer 14 years ago
parent
commit
963f8ff945
  1. 10
      ILSpy.BamlDecompiler/CecilType.cs
  2. 11
      ILSpy.BamlDecompiler/CecilTypeResolver.cs
  3. 11
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs
  4. 6
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs
  5. 3
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs
  6. 2
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ITypeResolver.cs
  7. 36
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs
  8. 18
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

10
ILSpy.BamlDecompiler/CecilType.cs

@ -67,5 +67,15 @@ namespace ILSpy.BamlDecompiler @@ -67,5 +67,15 @@ namespace ILSpy.BamlDecompiler
{
return string.Format("[CecilType Type={0}]", type);
}
public IType BaseType {
get {
TypeDefinition td = type.BaseType.Resolve();
if (td == null)
throw new Exception("could not resolve '" + type.BaseType.FullName + "'!");
return new CecilType(td);
}
}
}
}

11
ILSpy.BamlDecompiler/CecilTypeResolver.cs

@ -23,6 +23,11 @@ namespace ILSpy.BamlDecompiler @@ -23,6 +23,11 @@ namespace ILSpy.BamlDecompiler
this.thisAssembly = asm;
}
public bool IsLocalAssembly(string name)
{
return name == this.thisAssembly.Name.Name;
}
public IType GetTypeByAssemblyQualifiedName(string name)
{
int comma = name.IndexOf(',');
@ -51,5 +56,11 @@ namespace ILSpy.BamlDecompiler @@ -51,5 +56,11 @@ namespace ILSpy.BamlDecompiler
return new CecilDependencyPropertyDescriptor(name, ((CecilType)ownerType).type);
}
public string RuntimeVersion {
get {
return thisAssembly.MainModule.Runtime.ToString();
}
}
}
}

11
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs

@ -131,6 +131,17 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -131,6 +131,17 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return null;
}
}
public bool IsLocalAssembly(string name)
{
return false;
}
public string RuntimeVersion {
get {
throw new NotImplementedException();
}
}
#endregion

6
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs

@ -42,6 +42,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -42,6 +42,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (_type == null) return false;
return this._type.Equals(((DotNetType)type).Type);
}
public IType BaseType {
get {
return new DotNetType(this._type.BaseType.AssemblyQualifiedName);
}
}
#endregion

3
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs

@ -8,10 +8,11 @@ using System.Text; @@ -8,10 +8,11 @@ using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
/// <summary>
/// Interface rappresenting a DotNet type
/// Interface representing a DotNet type
/// </summary>
public interface IType
{
IType BaseType { get; }
string AssemblyQualifiedName { get; }
bool IsSubclassOf(IType type);
bool Equals(IType type);

2
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ITypeResolver.cs

@ -9,6 +9,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -9,6 +9,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{
public interface ITypeResolver
{
string RuntimeVersion { get; }
bool IsLocalAssembly(string name);
IType GetTypeByAssemblyQualifiedName(string name);
IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType);
}

36
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs

@ -34,12 +34,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -34,12 +34,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public KnownInfo(ITypeResolver resolver)
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
switch (resolver.RuntimeVersion) {
case "Net_2_0":
LoadKnownAssemblies30();
break;
case "Net_4_0":
LoadKnownAssemblies40();
break;
default:
throw new NotSupportedException();
}
KnownTypeTable = new TypeDeclaration[760];
KnownTypeTable[0] = new TypeDeclaration(resolver, string.Empty, string.Empty, 0);
@ -1305,6 +1309,26 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1305,6 +1309,26 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
KnownResourceTable.Add(0xa9, new ResourceName("SystemParameters.WorkArea"));
}
void LoadKnownAssemblies30()
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
}
void LoadKnownAssemblies40()
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
}
#endregion
public bool IsKnownType(string type)

18
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -8,6 +8,7 @@ using System.ComponentModel; @@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
@ -445,7 +446,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -445,7 +446,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
break;
default:
throw new NotImplementedException("UnsupportedNode: " + currentType);
break;
}
}
@ -1182,6 +1182,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1182,6 +1182,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
}
else
element = new XmlBamlElement();
// the type is defined in the local assembly, i.e., the main assembly
// and this is the root element
if (_resolver.IsLocalAssembly(declaration.Assembly) && parentElement == null) {
declaration = GetKnownTypeDeclarationByName(declaration.Type.BaseType.AssemblyQualifiedName);
}
element.TypeDeclaration = declaration;
elements.Push(element);
@ -1563,6 +1569,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1563,6 +1569,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return declaration;
}
TypeDeclaration GetKnownTypeDeclarationByName(string name)
{
foreach (var type in KnownInfo.KnownTypeTable) {
if (name == string.Format("{0}.{1}, {2}", type.Namespace, type.Name, type.Assembly))
return type;
}
throw new NotSupportedException();
}
internal string GetAssembly(short identifier)
{

Loading…
Cancel
Save