void RewriteClass(XamlContext ctx, XElement elem) { var type = elem.Annotation<XamlType>(); if (type == null || type.ResolvedType == null) return; var typeDef = type.ResolvedType.ResolveTypeDef(); var comparer = new AssemblyNameComparer(AssemblyNameComparerFlags.All); if (typeDef == null || !comparer.Equals(typeDef.DefinitionAssembly, ctx.Module.Assembly)) return; var newType = typeDef.BaseType; var xamlType = new XamlType(newType.DefinitionAssembly, newType.ReflectionNamespace, newType.Name); xamlType.ResolveNamespace(elem, ctx); elem.Name = xamlType.ToXName(ctx); var attrName = ctx.GetXamlNsName("Class", elem); var attrs = elem.Attributes().ToList(); if (typeDef.IsNotPublic) { var classModifierName = ctx.GetXamlNsName("ClassModifier", elem); attrs.Insert(0, new XAttribute(classModifierName, ctx.BamlDecompilerOptions.InternalClassModifier)); } attrs.Insert(0, new XAttribute(attrName, type.ResolvedType.ReflectionFullName)); elem.ReplaceAttributes(attrs); }
public bool IsAttachedTo(XamlType type) { if (type == null || ResolvedMember == null || type.ResolvedType == null) return true; var declType = ResolvedMember.DeclaringType; var t = type.ResolvedType; var comparer = new SigComparer(); do { if (comparer.Equals(t, declType)) return false; t = t.GetBaseType(); } while (t != null); return true; }
public XamlType ResolveType(ushort id) { XamlType xamlType; if (typeMap.TryGetValue(id, out xamlType)) return xamlType; ITypeDefOrRef type; IAssembly assembly; if (id > 0x7fff) { type = Baml.KnownThings.Types((KnownTypes)(-id)); assembly = type.DefinitionAssembly; } else { var typeRec = Baml.TypeIdMap[id]; assembly = Baml.ResolveAssembly(typeRec.AssemblyId); type = TypeNameParser.ParseReflectionThrow(Module, typeRec.TypeFullName, new DummyAssemblyRefFinder(assembly)); } var clrNs = type.ReflectionNamespace; var xmlNs = XmlNs.LookupXmlns(assembly, clrNs); typeMap[id] = xamlType = new XamlType(assembly, clrNs, type.ReflectionName, GetXmlNamespace(xmlNs)) { ResolvedType = type }; return xamlType; }
public static string ToString(this XamlContext ctx, XElement elem, XamlType type) { type.ResolveNamespace(elem, ctx); return ctx.ToString(elem, type.ToXName(ctx)); }
public XamlExtension(XamlType type) { ExtensionType = type; NamedArguments = new Dictionary <string, object>(); }
public XamlProperty(XamlType type, string name) { DeclaringType = type; PropertyName = name; }
public XamlExtension(XamlType type) { ExtensionType = type; NamedArguments = new Dictionary<string, object>(); }
public static string ToString(this XamlContext ctx, XElement elem, XamlType type) { type.ResolveNamespace(elem, ctx); return(ctx.ToString(elem, type.ToXName(ctx))); }