public void ManageNamespace(XamlReader reader) { switch (reader.NodeType) { case XamlNodeType.NamespaceDeclaration: tempNamespaceList.Add(reader.Namespace.Prefix, new NamespaceDeclaration( XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(reader.Namespace.Namespace, this.localAssemblyName), reader.Namespace.Prefix)); break; case XamlNodeType.StartObject: case XamlNodeType.StartMember: case XamlNodeType.GetObject: if (tempNamespaceList != null) { namespaceStack.Push(tempNamespaceList); tempNamespaceList = new Dictionary <string, NamespaceDeclaration>(); } break; case XamlNodeType.EndMember: case XamlNodeType.EndObject: namespaceStack.Pop(); break; default: break; } }
protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments) { XamlType xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); if (xamlType == null || xamlType.IsUnknown) { xamlNamespace = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(xamlNamespace, this.localAssemblyName, this.realAssemblyName); xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); } else if (!xamlType.UnderlyingType.Assembly.ReflectionOnly && xamlType.UnderlyingType.Assembly != typeof(object).Assembly) { // Types from XamlLanguage are live; but we want the ROL equivalent, so that we can validate // against expected member types. We do this by looking it up via its clr-namespace form. // Note this means that the resulting XamlType will only have its clr-namespace, not the XAML2006 namespace. IList <string> namespaces = xamlType.GetXamlNamespaces(); Fx.Assert(namespaces.Contains(XamlLanguage.Xaml2006Namespace) && xamlType.TypeArguments == null, "This should only happen for XamlLanguage types, none of which are generic"); string clrNamespace = namespaces[namespaces.Count - 1]; XamlType rolType = base.GetXamlType(clrNamespace, xamlType.UnderlyingType.Name); if (rolType != null) { xamlType = rolType; } } return(xamlType); }
public override IList <string> GetXamlNamespaces() { if (namespaces == null) { namespaces = new List <string>(); IList <string> originalNamespaces = base.GetXamlNamespaces(); foreach (var ns in originalNamespaces) { namespaces.Add(XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(ns, this.localAssemblyName, this.realAssemblyName)); } } return(namespaces); }
IList <XamlType> UpdateTypeArgs(IList <XamlType> typeArgs, XamlSchemaContext xsc) { if (typeArgs != null) { IList <XamlType> updatedTypeArgs = new List <XamlType>(); foreach (var typeArg in typeArgs) { IList <XamlType> typeArgTypeArgs = UpdateTypeArgs(typeArg.TypeArguments, xsc); string typeArgXmlns = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(typeArg.PreferredXamlNamespace, this.localAssemblyName); updatedTypeArgs.Add(new XamlType(typeArgXmlns, typeArg.Name, typeArgTypeArgs, xsc)); } return(updatedTypeArgs); } return(typeArgs); }
void WritestrippedXamlNode(XamlReader reader, XamlWriter writer) { switch (reader.NodeType) { case XamlNodeType.StartObject: XamlType xamlType = reader.Type; if (xamlType.IsUnknown) { IList <XamlType> typeArgs = UpdateTypeArgs(xamlType.TypeArguments, reader.SchemaContext); string xmlns = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(xamlType.PreferredXamlNamespace, this.localAssemblyName); xamlType = new XamlType(xmlns, xamlType.Name, typeArgs, reader.SchemaContext); } writer.WriteStartObject(xamlType); break; case XamlNodeType.StartMember: XamlMember member = reader.Member; if (member.IsUnknown && !member.IsDirective) { string xmlns = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(member.DeclaringType.PreferredXamlNamespace, this.localAssemblyName); XamlType memberXamlType = new XamlType(xmlns, member.DeclaringType.Name, member.DeclaringType.TypeArguments, reader.SchemaContext); member = new XamlMember(member.Name, memberXamlType, member.IsAttachable); } writer.WriteStartMember(member); break; case XamlNodeType.NamespaceDeclaration: NamespaceDeclaration ns = new NamespaceDeclaration( XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(reader.Namespace.Namespace, this.localAssemblyName), reader.Namespace.Prefix); writer.WriteNamespace(ns); break; case XamlNodeType.GetObject: case XamlNodeType.EndObject: case XamlNodeType.EndMember: case XamlNodeType.Value: case XamlNodeType.None: writer.WriteNode(reader); break; default: Debug.Fail("Unrecognized XamlNodeType value" + reader.NodeType.ToString()); break; } }