@ -42,11 +42,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -42,11 +42,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
sealed class XamlNamespace
{
{
internal readonly string XmlNamespacePrefix ;
internal readonly string XmlNamespace ;
internal XamlNamespace ( string xmlNamespace )
{
internal XamlNamespace ( string xmlNamespacePrefix , string xmlNamespace )
{
this . XmlNamespacePrefix = xmlNamespacePrefix ;
this . XmlNamespace = xmlNamespace ;
}
@ -54,7 +56,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -54,7 +56,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal XamlNamespace Clone ( )
{
XamlNamespace copy = new XamlNamespace ( this . XmlNamespace ) ;
XamlNamespace copy = new XamlNamespace ( this . XmlNamespacePrefix , this . XmlNamespace ) ;
// AssemblyNamespaceMapping is immutable
copy . ClrNamespaces . AddRange ( this . ClrNamespaces ) ;
return copy ;
@ -107,7 +109,25 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -107,7 +109,25 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else {
return "clr-namespace:" + mapping . Namespace + ";assembly=" + mapping . Assembly . GetName ( ) . Name ;
}
}
}
/// <summary>
/// Gets the prefix to use for the specified XML namespace,
/// or null if no suitable prefix could be found.
/// </summary>
public string GetPrefixForXmlNamespace ( string xmlNamespace )
{
XamlNamespace ns ;
if ( namespaces . TryGetValue ( xmlNamespace , out ns ) )
{
return ns . XmlNamespacePrefix ;
}
else
{
return null ;
}
}
XamlNamespace ParseNamespace ( string xmlNamespace )
{
@ -127,7 +147,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -127,7 +147,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
assembly = name . Substring ( "assembly=" . Length ) ;
}
XamlNamespace ns = new XamlNamespace ( xmlNamespace ) ;
XamlNamespace ns = new XamlNamespace ( null , xmlNamespace ) ;
Assembly asm = LoadAssembly ( assembly ) ;
if ( asm ! = null ) {
AddMappingToNamespace ( ns , new AssemblyNamespaceMapping ( asm , namespaceName ) ) ;
@ -154,11 +174,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -154,11 +174,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
public void RegisterAssembly ( Assembly assembly )
{
if ( assembly = = null )
throw new ArgumentNullException ( "assembly" ) ;
throw new ArgumentNullException ( "assembly" ) ;
Dictionary < string , string > namespacePrefixes = new Dictionary < string , string > ( ) ;
foreach ( XmlnsPrefixAttribute xmlnsPrefix in assembly . GetCustomAttributes ( typeof ( XmlnsPrefixAttribute ) , true ) ) {
namespacePrefixes . Add ( xmlnsPrefix . XmlNamespace , xmlnsPrefix . Prefix ) ;
}
foreach ( XmlnsDefinitionAttribute xmlnsDef in assembly . GetCustomAttributes ( typeof ( XmlnsDefinitionAttribute ) , true ) ) {
XamlNamespace ns ;
if ( ! namespaces . TryGetValue ( xmlnsDef . XmlNamespace , out ns ) ) {
ns = namespaces [ xmlnsDef . XmlNamespace ] = new XamlNamespace ( xmlnsDef . XmlNamespace ) ;
XamlNamespace ns ;
if ( ! namespaces . TryGetValue ( xmlnsDef . XmlNamespace , out ns ) ) {
string prefix ;
namespacePrefixes . TryGetValue ( xmlnsDef . XmlNamespace , out prefix ) ;
ns = namespaces [ xmlnsDef . XmlNamespace ] = new XamlNamespace ( prefix , xmlnsDef . XmlNamespace ) ;
}
if ( string . IsNullOrEmpty ( xmlnsDef . AssemblyName ) ) {
AddMappingToNamespace ( ns , new AssemblyNamespaceMapping ( assembly , xmlnsDef . ClrNamespace ) ) ;