Beispiel #1
0
        public bool Perform(
            string sourceNamespace,
            string objectClassName,
            string targetNamespace,
            ref string xaml,
            out XamlXmlns?newXmlns
            )
        {
            newXmlns = null;

            if (ClassName != objectClassName)
            {
                return(false);
            }

            if (Namespace != sourceNamespace)
            {
                return(false);
            }

            //match!

            var xPrefix = _xmlnsProvider.GetXPrefix();

            xaml = xaml.Substring(0, Index)
                   + $@"{xPrefix.Alias}:Class=""{targetNamespace}.{ClassName}"""
                   + xaml.Substring(Index + Length)
            ;
            return(true);
        }
        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);
        }