Ejemplo n.º 1
0
        private void UpdateRefNameUsingReplacement(string toBeReplaced, string replacement, RefNameReplacementPart partToBeReplaced)
        {
            Debug.Assert(!string.IsNullOrEmpty(toBeReplaced), "UpdateRefNameUsingReplacement: toBeReplaced must not null or empty");
            Debug.Assert(!string.IsNullOrEmpty(replacement), "UpdateRefNameUsingReplacement: replacement must not null or empty");
            if (string.IsNullOrEmpty(toBeReplaced) ||
                string.IsNullOrEmpty(replacement))
            {
                return;
            }

            // loop over all the references replacing toBeReplaced with
            // replacement if present in the correct part
            var origRefNameAsNormalizedNames = GetRefNameAsNormalizedNames();
            var replacementAttrValue         = new StringBuilder();
            var replacedAnyPart = false;
            var firstRef        = true;

            foreach (var normalizedName in origRefNameAsNormalizedNames)
            {
                // prepend the delimiter if this is not the first reference
                if (!firstRef)
                {
                    replacementAttrValue.Append(_delimiter);
                }
                else
                {
                    firstRef = false;
                }

                // Replace the appropriate part of the reference if necessary.
                // Note: replacementRefName will contain the reference with
                // the appropriate part replaced or the original reference if no
                // replacement is necessary.
                string replacementRefName;
                if (RefNameReplacementPart.NamespacePart == partToBeReplaced)
                {
                    if (normalizedName.ConstructBindingStringWithReplacedNamespace(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }
                else if (RefNameReplacementPart.AliasPart == partToBeReplaced)
                {
                    if (normalizedName.ConstructBindingStringWithReplacedAlias(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }
                else
                {
                    if (normalizedName.ConstructBindingStringWithReplacedNamePart(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }

                replacementAttrValue.Append(replacementRefName);
            }

            // if any replacement was made above then unbind the Binding and
            // replace the underlying attribute value
            var replacementString = replacementAttrValue.ToString();

            if (replacedAnyPart)
            {
                Debug.Assert(
                    replacementString != RefName,
                    "UpdateRefNameNamespaceOrAlias() is about to replace the following RefName with an identical value " + RefName);
                Unbind();
                SetXAttributeValue(replacementAttrValue.ToString());
            }
            else
            {
                Debug.Assert(
                    replacementString == RefName,
                    "UpdateRefNameNamespaceOrAlias() for RefName, " + RefName
                    + ", is about to ignore the following replacement string which is different " + replacementString);
            }
        }
Ejemplo n.º 2
0
        private void UpdateRefNameUsingReplacement(string toBeReplaced, string replacement, RefNameReplacementPart partToBeReplaced)
        {
            Debug.Assert(!string.IsNullOrEmpty(toBeReplaced), "toBeReplaced must not null or empty");
            Debug.Assert(!string.IsNullOrEmpty(replacement), "replacement must not null or empty");
            if (string.IsNullOrEmpty(toBeReplaced)
                ||
                string.IsNullOrEmpty(replacement))
            {
                return;
            }

            // loop over all the references replacing toBeReplaced with
            // replacement if present in the correct part
            // Note: origRefNameAsNormalizedNames will contain the references without any
            // surrounding 'IsTypeOf()', we rely on _isTypeOfs to keep track of those.
            var origRefNameAsNormalizedNames = GetRefNameAsNormalizedNames();

            if (origRefNameAsNormalizedNames.Count != _isTypeOfs.Count)
            {
                Debug.Fail(
                    "Expected origRefNameAsNormalizedNames.Count == _isTypeOfs.Count, but got origRefNameAsNormalizedNames.Count = "
                    + origRefNameAsNormalizedNames.Count + ", _isTypeOfs.Count = " + _isTypeOfs.Count);
                return;
            }

            var replacementAttrValue = new StringBuilder();
            var replacedAnyPart      = false;

            for (var i = 0; i < origRefNameAsNormalizedNames.Count; i++)
            {
                // prepend the delimiter if this is not the first reference
                if (i > 0)
                {
                    replacementAttrValue.Append(_delimiter);
                }

                // Replace the namespace part of the reference if necessary.
                // Note: replacementRefName will contain the reference with
                // the namespace replaced or the original reference if no
                // replacement is necessary.
                var    normalizedName = origRefNameAsNormalizedNames[i];
                var    isTypeOf       = _isTypeOfs[i];
                string replacementRefName;
                if (RefNameReplacementPart.NamespacePart == partToBeReplaced)
                {
                    if (normalizedName.ConstructBindingStringWithReplacedNamespace(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }
                else if (RefNameReplacementPart.AliasPart == partToBeReplaced)
                {
                    if (normalizedName.ConstructBindingStringWithReplacedAlias(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }
                else
                {
                    if (normalizedName.ConstructBindingStringWithReplacedNamePart(
                            toBeReplaced, replacement, out replacementRefName))
                    {
                        replacedAnyPart = true;
                    }
                }

                if (isTypeOf)
                {
                    replacementAttrValue.Append(EntityTypeMapping.IsTypeOf);
                    replacementAttrValue.Append(replacementRefName);
                    replacementAttrValue.Append(EntityTypeMapping.IsTypeOfTerminal);
                }
                else
                {
                    replacementAttrValue.Append(replacementRefName);
                }
            }

            // if any replacement was made above then unbind the Binding and
            // replace the underlying attribute value
            var replacementString = replacementAttrValue.ToString();

            if (replacedAnyPart)
            {
                Debug.Assert(
                    replacementString != RefName,
                    "EntityTypeMappingTypeNameBinding.UpdateRefNameNamespaces() is about to replace the following RefName with an identical value "
                    + RefName);
                Unbind();
                SetXAttributeValue(replacementAttrValue.ToString());
            }
            else
            {
                Debug.Assert(
                    replacementString == RefName,
                    "EntityTypeMappingTypeNameBinding.UpdateRefNameNamespaces() for RefName, " + RefName
                    + ", is about to ignore the following replacement string which is different " + replacementString);
            }
        }
Ejemplo n.º 3
0
        private void UpdateRefNameUsingReplacement(string toBeReplaced, string replacement, RefNameReplacementPart partToBeReplaced)
        {
            Debug.Assert(
                !string.IsNullOrEmpty(toBeReplaced),
                GetType().FullName + ".UpdateRefNameUsingReplacement(): toBeReplaced must not null or empty");
            Debug.Assert(
                !string.IsNullOrEmpty(replacement),
                GetType().FullName + ".UpdateRefNameUsingReplacement(): replacement must not null or empty");
            if (string.IsNullOrEmpty(toBeReplaced) ||
                string.IsNullOrEmpty(replacement))
            {
                return;
            }

            var refNameAsNormalizedNames = GetRefNameAsNormalizedNames();

            if (1 != refNameAsNormalizedNames.Count)
            {
                Debug.Fail(
                    GetType().FullName
                    + ".UpdateRefNameUsingReplacement(): expecting only 1 symbol from GetRefNameAsNormalizedNames(). Received "
                    + refNameAsNormalizedNames.Count);
                return;
            }

            // replace toBeReplaced with replacement if present in the correct part
            var    refNameAsNameRef = refNameAsNormalizedNames[0];
            var    madeReplacement  = false;
            string replacementRefName;

            if (RefNameReplacementPart.NamespacePart == partToBeReplaced)
            {
                if (refNameAsNameRef.ConstructBindingStringWithReplacedNamespace(
                        toBeReplaced, replacement, out replacementRefName))
                {
                    madeReplacement = true;
                }
            }
            else if (RefNameReplacementPart.AliasPart == partToBeReplaced)
            {
                if (refNameAsNameRef.ConstructBindingStringWithReplacedAlias(
                        toBeReplaced, replacement, out replacementRefName))
                {
                    madeReplacement = true;
                }
            }
            else
            {
                if (refNameAsNameRef.ConstructBindingStringWithReplacedNamePart(
                        toBeReplaced, replacement, out replacementRefName))
                {
                    madeReplacement = true;
                }
            }

            // if any replacement was made above then unbind the Binding and
            // replace the underlying attribute value
            if (madeReplacement)
            {
                Debug.Assert(
                    replacementRefName != RefName,
                    "UpdateRefNameNamespaceOrAlias() is about to replace the following RefName with an identical value " + RefName);
                Unbind();

                // For most scenarios, RefName should be equal to refNameAsNameRef.ToBindingString()
                // But in FunctionImport's Return, the values are as follow:
                // RefName : "Collection([Old Fully-qualifed EntityType/ComplexType])"
                // refNameasNameRef.ToBindingString(): [Old Fully-qualifed EntityType/ComplexType]
                // replacementRefName: [New Fully-qualifed EntityType/ComplexType]
                if (String.Compare(RefName, refNameAsNameRef.ToBindingString(), StringComparison.CurrentCulture) != 0)
                {
                    replacementRefName = RefName.Replace(refNameAsNameRef.ToBindingString(), replacementRefName);
                }
                SetXAttributeValue(replacementRefName);
            }
            else
            {
                Debug.Assert(
                    replacementRefName == RefName,
                    "UpdateRefNameNamespaceOrAlias() for RefName, " + RefName
                    + ", is about to ignore the following replacement string which is different " + replacementRefName);
            }
        }