Browse Source

add source of Ricciolo.StylesExplorer.MarkupReflection by Cristian Civera

pull/182/merge
Siegfried Pammer 14 years ago
parent
commit
71c8fb1446
  1. 25
      ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj
  2. 172
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs
  3. 112
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlAssembly.cs
  4. 47
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs
  5. 80
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlFile.cs
  6. 72
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlRecordType.cs
  7. 58
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs
  8. 14
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs
  9. 19
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs
  10. 15
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ITypeResolver.cs
  11. 1319
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs
  12. 58
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/PropertyDeclaration.cs
  13. 32
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ResourceName.cs
  14. 137
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/TypeDeclaration.cs
  15. 35
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/WpfDependencyPropertyDescriptor.cs
  16. 193
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs
  17. 21
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlNode.cs
  18. 86
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlProperty.cs
  19. 48
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs
  20. 1939
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  21. 33
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlText.cs
  22. 47
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlNamespace.cs
  23. 63
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlPIMapping.cs

25
ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj

@ -43,6 +43,31 @@ @@ -43,6 +43,31 @@
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\AppDomainTypeResolver.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\BamlAssembly.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\BamlBinaryReader.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\BamlFile.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\BamlRecordType.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\DotNetType.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\IDependencyPropertyDescriptor.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\IType.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\ITypeResolver.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\KnownInfo.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\PropertyDeclaration.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\ResourceName.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\TypeDeclaration.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\WpfDependencyPropertyDescriptor.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlElement.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlNode.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlProperty.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlPropertyElement.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlReader.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlText.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlNamespace.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlPIMapping.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Ricciolo.StylesExplorer.MarkupReflection" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

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

@ -0,0 +1,172 @@ @@ -0,0 +1,172 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.IO;
using System.Linq;
using Microsoft.Win32;
using System.Threading;
using System.Security.Permissions;
using System.Security;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public delegate void AssemblyResolveEventHandler(object s, AssemblyResolveEventArgs e);
public class AppDomainTypeResolver : MarshalByRefObject, ITypeResolver
{
private readonly AppDomain _domain;
private string baseDir;
public event AssemblyResolveEventHandler AssemblyResolve;
public static AppDomainTypeResolver GetIntoNewAppDomain(string baseDir)
{
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = Environment.CurrentDirectory;
AppDomain domain = AppDomain.CreateDomain("AppDomainTypeResolver", null, info, new PermissionSet(PermissionState.Unrestricted));
AppDomainTypeResolver resolver = (AppDomainTypeResolver)domain.CreateInstanceAndUnwrap(typeof(AppDomainTypeResolver).Assembly.FullName,
typeof(AppDomainTypeResolver).FullName, false, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new object[] { domain, baseDir }, null, null, null);
return resolver;
}
Assembly domain_AssemblyResolve(object sender, ResolveEventArgs args)
{
// Cerco di risolvere automaticamente
AssemblyName name = new AssemblyName(args.Name);
string fileName = Path.Combine(this.baseDir, name.Name + ".exe");
if (!File.Exists(fileName))
fileName = Path.Combine(this.baseDir, name.Name + ".dll");
// Carico il percorso autocalcolato
if (File.Exists(fileName))
return Assembly.LoadFile(fileName);
if (AssemblyResolve != null)
{
AssemblyResolveEventArgs e = new AssemblyResolveEventArgs(args.Name, this.baseDir);
AssemblyResolve(this, e);
if (!String.IsNullOrEmpty(e.Location) && File.Exists(e.Location))
return Assembly.LoadFile(e.Location);
}
return null;
}
public static void DestroyResolver(AppDomainTypeResolver resolver)
{
if (resolver == null) throw new ArgumentNullException("resolver");
ThreadPool.QueueUserWorkItem(delegate
{
AppDomain.Unload(resolver.Domain);
});
}
protected AppDomainTypeResolver(AppDomain domain, string baseDir)
{
_domain = domain;
this.baseDir = baseDir;
domain.AssemblyResolve += new ResolveEventHandler(domain_AssemblyResolve);
}
public BamlAssembly LoadAssembly(AssemblyName asm)
{
//return new BamlAssembly(Assembly.Load(asm));
return new BamlAssembly(_domain.Load(asm));
}
public BamlAssembly LoadAssembly(string location)
{
Assembly asm = Assembly.LoadFile(location);
return new BamlAssembly(asm);
//return _domain.Load(System.IO.File.ReadAllBytes(location));
//return Assembly.LoadFrom(location);
}
public BamlAssembly[] GetReferencedAssemblies(BamlAssembly asm)
{
AssemblyName[] list = asm.Assembly.GetReferencedAssemblies();
return (from an in list
select this.LoadAssembly(an)).ToArray();
}
public AppDomain Domain
{
get { return _domain; }
}
#region ITypeResolver Members
public IType GetTypeByAssemblyQualifiedName(string name)
{
return new DotNetType(name);
}
public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType)
{
if (name == null) throw new ArgumentNullException("name");
if (ownerType == null) throw new ArgumentNullException("ownerType");
if (targetType == null) throw new ArgumentNullException("targetType");
Type dOwnerType = ((DotNetType)ownerType).Type;
Type dTargetType = ((DotNetType)targetType).Type;
try
{
DependencyPropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromName(name, dOwnerType, dTargetType);
if (propertyDescriptor != null)
return new WpfDependencyPropertyDescriptor(propertyDescriptor);
return null;
}
catch (Exception)
{
return null;
}
}
#endregion
public override object InitializeLifetimeService()
{
return null;
}
}
public class AssemblyResolveEventArgs : MarshalByRefObject
{
private string _location;
private string _name;
private string _baseDir;
public AssemblyResolveEventArgs(string name, string baseDir)
{
_name = name;
_baseDir = baseDir;
}
public string Location
{
get { return _location; }
set { _location = value; }
}
public string Name
{
get { return _name; }
}
public string BaseDir
{
get { return _baseDir; }
}
}
}

112
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlAssembly.cs

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public class BamlAssembly : MarshalByRefObject
{
private readonly string _filePath;
private Assembly _assembly;
private BamlFileList _bamlFile;
public BamlAssembly(Assembly assembly)
{
_assembly = assembly;
_filePath = assembly.CodeBase;
ReadBaml();
}
public BamlAssembly(string filePath)
{
this._filePath = Path.GetFullPath(filePath);
this._assembly = Assembly.LoadFile(this.FilePath);
if (String.Compare(this.Assembly.CodeBase, this.FilePath, true) != 0)
throw new ArgumentException("Cannot load filePath because Assembly is already loaded", "filePath");
ReadBaml();
}
private void ReadBaml()
{
// Get available names
string[] resources = this.Assembly.GetManifestResourceNames();
foreach (string res in resources)
{
// Solo le risorse
if (String.Compare(Path.GetExtension(res), ".resources", true) != 0) continue;
// Get stream
using (Stream stream = this.Assembly.GetManifestResourceStream(res))
{
try
{
ResourceReader reader = new ResourceReader(stream);
foreach (DictionaryEntry entry in reader)
{
if (String.Compare(Path.GetExtension(entry.Key.ToString()), ".baml", true) == 0 && entry.Value is Stream)
{
BamlFile bm = new BamlFile(GetAssemblyResourceUri(entry.Key.ToString()), (Stream)entry.Value);
this.BamlFiles.Add(bm);
}
}
}
catch (ArgumentException)
{}
}
}
}
private Uri GetAssemblyResourceUri(string resourceName)
{
AssemblyName asm = this.Assembly.GetName();
byte[] data = asm.GetPublicKeyToken();
StringBuilder token = new StringBuilder(data.Length * 2);
for (int x = 0; x < data.Length; x++)
{
token.Append(data[x].ToString("x", System.Globalization.CultureInfo.InvariantCulture));
}
return new Uri(String.Format(@"{0};V{1};{2};component\{3}", asm.Name, asm.Version, token, Path.ChangeExtension(resourceName, ".xaml")), UriKind.RelativeOrAbsolute);
}
public string FilePath
{
get { return _filePath; }
}
public Assembly Assembly
{
get { return _assembly; }
}
public BamlFileList BamlFiles
{
get
{
if (_bamlFile == null)
_bamlFile = new BamlFileList();
return _bamlFile;
}
}
public override object InitializeLifetimeService()
{
return null;
}
}
[Serializable()]
public class BamlFileList : Collection<BamlFile>
{}
}

47
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.IO;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class BamlBinaryReader : BinaryReader
{
// Methods
public BamlBinaryReader(Stream stream)
: base(stream)
{
}
public virtual double ReadCompressedDouble()
{
switch (this.ReadByte())
{
case 1:
return 0;
case 2:
return 1;
case 3:
return -1;
case 4:
{
double num = this.ReadInt32();
return (num * 1E-06);
}
case 5:
return this.ReadDouble();
}
throw new NotSupportedException();
}
public int ReadCompressedInt32()
{
return base.Read7BitEncodedInt();
}
}
}

80
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlFile.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Resources;
using System.Text;
using System.Windows;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
/// <summary>
/// Rappresenta un singole file Baml all'interno di un assembly
/// </summary>
public class BamlFile : Component
{
private Uri _uri;
private readonly Stream _stream;
public BamlFile(Uri uri, Stream stream)
{
if (uri == null)
new ArgumentNullException("uri");
if (stream == null)
throw new ArgumentNullException("stream");
_uri = uri;
_stream = stream;
}
/// <summary>
/// Carica il Baml attraverso il motore di WPF con Application.LoadComponent
/// </summary>
/// <returns></returns>
public object LoadContent()
{
try
{
return Application.LoadComponent(this.Uri);
}
catch (Exception e)
{
throw new InvalidOperationException("Invalid baml file.", e);
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
this.Stream.Dispose();
}
public override object InitializeLifetimeService()
{
return null;
}
/// <summary>
/// Restituisce lo stream originale contenente il Baml
/// </summary>
public Stream Stream
{
get { return _stream; }
}
/// <summary>
/// Restituisce l'indirizzo secondo lo schema pack://
/// </summary>
public Uri Uri
{
get { return _uri; }
}
}
}

72
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlRecordType.cs

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal enum BamlRecordType : byte
{
AssemblyInfo = 0x1c,
AttributeInfo = 0x1f,
ClrEvent = 0x13,
Comment = 0x17,
ConnectionId = 0x2d,
ConstructorParametersEnd = 0x2b,
ConstructorParametersStart = 0x2a,
ConstructorParameterType = 0x2c,
ContentProperty = 0x2e,
DefAttribute = 0x19,
DefAttributeKeyString = 0x26,
DefAttributeKeyType = 0x27,
DeferableContentStart = 0x25,
DefTag = 0x18,
DocumentEnd = 2,
DocumentStart = 1,
ElementEnd = 4,
ElementStart = 3,
EndAttributes = 0x1a,
KeyElementEnd = 0x29,
KeyElementStart = 40,
LastRecordType = 0x39,
LineNumberAndPosition = 0x35,
LinePosition = 0x36,
LiteralContent = 15,
NamedElementStart = 0x2f,
OptimizedStaticResource = 0x37,
PIMapping = 0x1b,
PresentationOptionsAttribute = 0x34,
ProcessingInstruction = 0x16,
Property = 5,
PropertyArrayEnd = 10,
PropertyArrayStart = 9,
PropertyComplexEnd = 8,
PropertyComplexStart = 7,
PropertyCustom = 6,
PropertyDictionaryEnd = 14,
PropertyDictionaryStart = 13,
PropertyListEnd = 12,
PropertyListStart = 11,
PropertyStringReference = 0x21,
PropertyTypeReference = 0x22,
PropertyWithConverter = 0x24,
PropertyWithExtension = 0x23,
PropertyWithStaticResourceId = 0x38,
RoutedEvent = 0x12,
StaticResourceEnd = 0x31,
StaticResourceId = 50,
StaticResourceStart = 0x30,
StringInfo = 0x20,
Text = 0x10,
TextWithConverter = 0x11,
TextWithId = 0x33,
TypeInfo = 0x1d,
TypeSerializerInfo = 30,
Unknown = 0,
XmlAttribute = 0x15,
XmlnsProperty = 20
}
}

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

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public class DotNetType : MarshalByRefObject, IType
{
private readonly string _assemblyQualifiedName;
private Type _type;
public DotNetType(string assemblyQualifiedName)
{
if (assemblyQualifiedName == null) throw new ArgumentNullException("assemblyQualifiedName");
_assemblyQualifiedName = assemblyQualifiedName;
_type = Type.GetType(assemblyQualifiedName, false, true);
}
#region IType Members
public string AssemblyQualifiedName
{
get { return _assemblyQualifiedName; }
}
public bool IsSubclassOf(IType type)
{
if (type == null) throw new ArgumentNullException("type");
if (!(type is DotNetType)) throw new ArgumentException("type");
if (_type == null) return false;
return this._type.IsSubclassOf(((DotNetType)type).Type);
}
public bool Equals(IType type)
{
if (type == null) throw new ArgumentNullException("type");
if (!(type is DotNetType)) throw new ArgumentException("type");
if (_type == null) return false;
return this._type.Equals(((DotNetType)type).Type);
}
#endregion
public Type Type
{
get { return _type; }
}
public override object InitializeLifetimeService()
{
return null;
}
}
}

14
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IDependencyPropertyDescriptor.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public interface IDependencyPropertyDescriptor
{
bool IsAttached { get; }
}
}

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

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
/// <summary>
/// Interface rappresenting a DotNet type
/// </summary>
public interface IType
{
string AssemblyQualifiedName { get; }
bool IsSubclassOf(IType type);
bool Equals(IType type);
}
}

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

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public interface ITypeResolver
{
IType GetTypeByAssemblyQualifiedName(string name);
IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType);
}
}

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

File diff suppressed because it is too large Load Diff

58
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/PropertyDeclaration.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class PropertyDeclaration
{
private TypeDeclaration declaringType;
private string name;
// Methods
public PropertyDeclaration(string name)
{
this.name = name;
this.declaringType = null;
}
public PropertyDeclaration(string name, TypeDeclaration declaringType)
{
this.name = name;
this.declaringType = declaringType;
}
public override string ToString()
{
if (((this.DeclaringType != null) && (this.DeclaringType.Name == "XmlNamespace")) && ((this.DeclaringType.Namespace == null) && (this.DeclaringType.Assembly == null)))
{
if ((this.Name == null) || (this.Name.Length == 0))
{
return "xmlns";
}
return ("xmlns:" + this.Name);
}
return this.Name;
}
// Properties
public TypeDeclaration DeclaringType
{
get
{
return this.declaringType;
}
}
public string Name
{
get
{
return this.name;
}
}
}
}

32
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ResourceName.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public class ResourceName
{
private string name;
public ResourceName(string name)
{
this.name = name;
}
public override string ToString()
{
return this.Name;
}
public string Name
{
get
{
return this.name;
}
}
}
}

137
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/TypeDeclaration.cs

@ -0,0 +1,137 @@ @@ -0,0 +1,137 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class TypeDeclaration
{
private readonly XmlBamlReader reader;
private readonly short _assemblyId;
private readonly bool _isKnown;
private readonly string _name;
private readonly string _namespaceName;
private readonly bool _isExtension;
private IType _type;
private bool _typeLoaded;
private readonly ITypeResolver resolver;
public TypeDeclaration(ITypeResolver resolver, string name, string namespaceName, short assemblyId)
: this(null, resolver, name, namespaceName, assemblyId, true)
{
}
public TypeDeclaration(ITypeResolver resolver, string name, string namespaceName, short assemblyId, bool isExtension)
: this(null, resolver, name, namespaceName, assemblyId, true)
{
_isExtension = isExtension;
}
public TypeDeclaration(XmlBamlReader reader, ITypeResolver resolver, string name, string namespaceName, short assemblyId)
: this(reader, resolver, name, namespaceName, assemblyId, true)
{
}
public TypeDeclaration(XmlBamlReader reader, ITypeResolver resolver, string name, string namespaceName, short assemblyId, bool isKnown)
{
this.reader = reader;
this.resolver = resolver;
this._name = name;
this._namespaceName = namespaceName;
this._assemblyId = assemblyId;
this._isKnown = isKnown;
if (!_isExtension)
_isExtension = name.EndsWith("Extension");
}
public override string ToString()
{
return this._name;
}
public bool IsExtension
{
get { return _isExtension; }
}
public string Assembly
{
get
{
if (reader != null)
return this.reader.GetAssembly(this.AssemblyId);
else
return KnownInfo.KnownAssemblyTable[this.AssemblyId];
}
}
public short AssemblyId
{
get { return _assemblyId; }
}
public string Name
{
get
{
return this._name;
}
}
public bool IsKnown
{
get { return _isKnown; }
}
//public Type DotNetType
//{
// get
// {
// if (!_typeLoaded)
// {
// _type = Type.GetType(String.Format("{0}.{1}, {2}", this.Namespace, this.Name, this.Assembly), false, true);
// _typeLoaded = true;
// }
// return _type;
// }
//}
public IType Type
{
get
{
if (!_typeLoaded)
{
if (this.Name.Length > 0)
_type = resolver.GetTypeByAssemblyQualifiedName(String.Format("{0}.{1}, {2}", this.Namespace, this.Name, this.Assembly));
_typeLoaded = true;
}
return _type;
}
}
public string Namespace
{
get
{
return this._namespaceName;
}
}
public override bool Equals(object obj)
{
TypeDeclaration td = obj as TypeDeclaration;
if (td != null)
return (this.Name == td.Name && this.Namespace == td.Namespace && this.AssemblyId == td.AssemblyId);
else
return false;
}
}
}

35
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/WpfDependencyPropertyDescriptor.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
public class WpfDependencyPropertyDescriptor : MarshalByRefObject, IDependencyPropertyDescriptor
{
private readonly DependencyPropertyDescriptor _propertyDescriptor;
public WpfDependencyPropertyDescriptor(DependencyPropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor == null) throw new ArgumentNullException("propertyDescriptor");
_propertyDescriptor = propertyDescriptor;
}
#region IDependencyPropertyDescriptor Members
public bool IsAttached
{
get { return _propertyDescriptor.IsAttached; }
}
#endregion
public override object InitializeLifetimeService()
{
return null;
}
}
}

193
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs

@ -0,0 +1,193 @@ @@ -0,0 +1,193 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlBamlElement : XmlBamlNode
{
private ArrayList _arguments = new ArrayList();
private XmlNamespaceCollection _namespaces = new XmlNamespaceCollection();
private TypeDeclaration _typeDeclaration;
private KeysResourcesCollection _keysResources = new KeysResourcesCollection();
private long _position;
public XmlBamlElement()
{
}
public XmlBamlElement(XmlBamlElement parent)
{
this.Namespaces.AddRange(parent.Namespaces);
}
public XmlNamespaceCollection Namespaces
{
get { return _namespaces; }
}
public TypeDeclaration TypeDeclaration
{
get
{
return this._typeDeclaration;
}
set
{
this._typeDeclaration = value;
}
}
public override XmlNodeType NodeType
{
get
{
return XmlNodeType.Element;
}
}
public long Position
{
get { return _position; }
set { _position = value; }
}
public override string ToString()
{
return String.Format("Element: {0}", TypeDeclaration.Name);
}
}
internal class XmlBamlEndElement : XmlBamlElement
{
public XmlBamlEndElement(XmlBamlElement start)
{
this.TypeDeclaration = start.TypeDeclaration;
this.Namespaces.AddRange(start.Namespaces);
}
public override XmlNodeType NodeType
{
get
{
return XmlNodeType.EndElement;
}
}
public override string ToString()
{
return String.Format("EndElement: {0}", TypeDeclaration.Name);
}
}
internal class KeyMapping
{
private string _key;
private TypeDeclaration _declaration;
private string _trueKey;
public KeyMapping(string key, TypeDeclaration declaration, string trueKey)
{
_key = key;
_declaration = declaration;
_trueKey = trueKey;
}
public string Key
{
get { return _key; }
}
public TypeDeclaration Declaration
{
get { return _declaration; }
}
public string TrueKey
{
get { return _trueKey; }
}
public override string ToString()
{
return String.Format("{0} - {1} - {2}", Key, Declaration, TrueKey);
}
}
internal class KeysResourcesCollection : List<KeysResource>
{
public KeysResource Last
{
get
{
if (this.Count == 0)
return null;
return this[this.Count - 1];
}
}
public KeysResource First
{
get
{
if (this.Count == 0)
return null;
return this[0];
}
}
}
internal class KeysResource
{
private KeysTable _keys = new KeysTable();
private ArrayList _staticResources = new ArrayList();
public KeysTable Keys
{
get { return _keys; }
}
public ArrayList StaticResources
{
get { return _staticResources; }
}
}
internal class KeysTable
{
private Hashtable table = new Hashtable();
public String this[long position]
{
get
{
return (string)this.table[position];
}
set
{
this.table[position] = value;
}
}
public int Count
{
get { return this.table.Count; }
}
public void Remove(long position)
{
this.table.Remove(position);
}
public bool HasKey(long position)
{
return this.table.ContainsKey(position);
}
}
}

21
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlNode.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlBamlNode
{
public virtual XmlNodeType NodeType
{
get { return XmlNodeType.None;}
}
}
internal class XmlBamlNodeCollection : List<XmlBamlNode>
{}
}

86
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlProperty.cs

@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlBamlProperty : XmlBamlNode
{
private PropertyDeclaration propertyDeclaration;
private PropertyType propertyType;
private object value;
public XmlBamlProperty(PropertyType propertyType)
{
this.propertyType = propertyType;
}
public XmlBamlProperty(PropertyType propertyType, PropertyDeclaration propertyDeclaration)
{
this.propertyDeclaration = propertyDeclaration;
this.propertyType = propertyType;
}
public override string ToString()
{
return this.PropertyDeclaration.Name;
}
public PropertyDeclaration PropertyDeclaration
{
get
{
return this.propertyDeclaration;
}
set
{
this.propertyDeclaration = value;
}
}
public PropertyType PropertyType
{
get
{
return this.propertyType;
}
}
public object Value
{
get
{
return this.value;
}
set
{
this.value = value;
}
}
public override XmlNodeType NodeType
{
get
{
return XmlNodeType.Attribute;
}
}
}
internal enum PropertyType
{
Key,
Value,
Content,
List,
Dictionary,
Complex
}
internal class XmlBamlPropertyCollection : List<XmlBamlNode>
{ }
}

48
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlBamlPropertyElement : XmlBamlElement
{
private readonly PropertyType _propertyType;
private PropertyDeclaration propertyDeclaration;
public XmlBamlPropertyElement(PropertyType propertyType, PropertyDeclaration propertyDeclaration)
{
_propertyType = propertyType;
this.propertyDeclaration = propertyDeclaration;
}
public XmlBamlPropertyElement(XmlBamlElement parent, PropertyType propertyType, PropertyDeclaration propertyDeclaration)
: base(parent)
{
_propertyType = propertyType;
this.propertyDeclaration = propertyDeclaration;
this.TypeDeclaration = propertyDeclaration.DeclaringType;
}
public PropertyDeclaration PropertyDeclaration
{
get
{
return this.propertyDeclaration;
}
}
public PropertyType PropertyType
{
get { return _propertyType; }
}
public override string ToString()
{
return String.Format("PropertyElement: {0}.{1}", TypeDeclaration.Name, PropertyDeclaration.Name);
}
}
}

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

File diff suppressed because it is too large Load Diff

33
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlText.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlBamlText : XmlBamlNode
{
private string _text;
public XmlBamlText(string text)
{
_text = text;
}
public string Text
{
get { return _text; }
}
public override System.Xml.XmlNodeType NodeType
{
get
{
return XmlNodeType.Text;
}
}
}
}

47
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlNamespace.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System.Collections.Generic;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class XmlNamespace
{
private string _prefix;
private string _namespace;
public XmlNamespace(string prefix, string ns)
{
_prefix = prefix;
_namespace = ns;
}
public string Prefix
{
get { return _prefix; }
}
public string Namespace
{
get { return _namespace; }
}
public override bool Equals(object obj)
{
if (obj is XmlNamespace)
{
XmlNamespace o = (XmlNamespace)obj;
return (o.Prefix.Equals(this.Prefix) && o.Namespace.Equals(this.Namespace));
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return _prefix.GetHashCode() + _namespace.GetHashCode() >> 20;
}
}
internal class XmlNamespaceCollection : List<XmlNamespace>
{}
}

63
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlPIMapping.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// Copyright (c) Cristian Civera (cristian@aspitalia.com)
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
/// <summary>
/// Rappresenta la mappatura tra namespace XML e namespace CLR con relativo assembly
/// </summary>
public class XmlPIMapping
{
private string _xmlNamespace;
private short _assemblyId;
private string _clrNamespace;
private static XmlPIMapping _default = new XmlPIMapping(PresentationNamespace, 0, String.Empty);
public const string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml";
public const string PresentationNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
public const string PresentationOptionsNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation/options";
public const string McNamespace = "http://schemas.openxmlformats.org/markup-compatibility/2006";
public XmlPIMapping(string xmlNamespace, short assemblyId, string clrNamespace)
{
_xmlNamespace = xmlNamespace;
_assemblyId = assemblyId;
_clrNamespace = clrNamespace;
}
/// <summary>
/// Restituisce o imposta il namespace XML
/// </summary>
public string XmlNamespace
{
get { return _xmlNamespace; }
set { _xmlNamespace = value;}
}
/// <summary>
/// Restituisce l'id dell'assembly
/// </summary>
public short AssemblyId
{
get { return _assemblyId; }
}
/// <summary>
/// Restituisce il namespace clr
/// </summary>
public string ClrNamespace
{
get { return _clrNamespace; }
}
/// <summary>
/// Restituisce il mapping di default di WPF
/// </summary>
public static XmlPIMapping Presentation
{
get { return _default; }
}
}
}
Loading…
Cancel
Save