public XamlXmlns( XamlXmlns xmlns, string targetNamespace ) { Index = xmlns.Index + Length; Length = 0; Alias = GetLastWord(targetNamespace) + GetPartOfGuid(); Namespace = targetNamespace; Saved = false; Suffix = xmlns.Suffix; }
private IEnumerable <XamlXmlns> ReadXmlns() { var matches = Regex.Matches(_xaml, @"xmlns:([\w\d]+)=""clr-namespace:([\w\d._]+)([^""]*)"""); foreach (Match match in matches) { var xx = new XamlXmlns( match.Index, match.Length, match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value ); yield return(xx); } }
public bool Perform( string sourceNamespace, string objectClassName, string targetNamespace, ref string xaml, out XamlXmlns?newXmlns ) { if (sourceNamespace == null) { throw new ArgumentNullException(nameof(sourceNamespace)); } if (objectClassName == null) { throw new ArgumentNullException(nameof(objectClassName)); } if (targetNamespace == null) { throw new ArgumentNullException(nameof(targetNamespace)); } if (xaml == null) { throw new ArgumentNullException(nameof(xaml)); } newXmlns = null; if (ClassName != objectClassName) { return(false); } var sourceXmlns = _xmlnsProvider.GetByAlias(Alias); if (sourceXmlns.Namespace != sourceNamespace) { return(false); } //match! //get or create new xmlns var targetXmlns = _xmlnsProvider.TryGetByNamespace(targetNamespace); if (targetXmlns == null) { targetXmlns = new XamlXmlns( sourceXmlns, targetNamespace ); newXmlns = targetXmlns; } var xPrefix = _xmlnsProvider.GetXPrefix(); xaml = xaml.Substring(0, Index) + $"{{{xPrefix.Alias}:{Prefix} {targetXmlns.Alias}:{ClassName}" + xaml.Substring(Index + Length) ; return(true); }