src/Misc/EFTools/EntityDesign/VisualStudio/EdmUtils.cs
// <summary>
//     Returns a string which is valid as a model namespace given the
//     proposedModelNamespace as a starting point.
// </summary>
// <param name="proposedModelNamespace">The proposed model namespace</param>
// <param name="defaultModelNamespace">The model namespace to use if removal of invalid chars results in an empty string</param>
Returns a string which is valid as a model namespace given the
proposedModelNamespace as a starting point.
Returns a string which is valid as a model namespace given the proposedModelNamespace as a starting point .
internal static string ConstructValidModelNamespace(string proposedModelNamespace, string defaultModelNamespace)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(defaultModelNamespace), "defaultModelNamespace must not be null or empty");
            if (IsValidModelNamespace(proposedModelNamespace))
            {
                return proposedModelNamespace;
            }
            if (String.IsNullOrEmpty(proposedModelNamespace))
            {
                return defaultModelNamespace;
            }
            var trialModelNamespace = proposedModelNamespace.Replace("<", "").Replace(">", "").Replace("&", "");
            if (!EscherAttributeContentValidator.IsValidXmlAttributeValue(trialModelNamespace)
                || string.IsNullOrEmpty(trialModelNamespace))
            {
                return defaultModelNamespace;
            }
            if (IsValidModelNamespace(trialModelNamespace))
            {
                return trialModelNamespace;
            }
            while (trialModelNamespace.Length > 0
                   && !Char.IsLetter(trialModelNamespace[0]))
            {
                trialModelNamespace = trialModelNamespace.Substring(1);
            }
            if (String.IsNullOrEmpty(trialModelNamespace))
            {
                return defaultModelNamespace;
            }
            if (IsValidModelNamespace(trialModelNamespace))
            {
                return trialModelNamespace;
            }
            trialModelNamespace += "1";
            if (IsValidModelNamespace(trialModelNamespace))
            {
                return trialModelNamespace;
            }
            return defaultModelNamespace;
        }
internal static string ConstructValidModelNamespace ( string proposedModelNamespace , string defaultModelNamespace ) { Debug . Assert ( ! string . IsNullOrWhiteSpace ( defaultModelNamespace ) , " " ) ; if ( IsValidModelNamespace ( proposedModelNamespace ) ) { return proposedModelNamespace ; } if ( String . IsNullOrEmpty ( proposedModelNamespace ) ) { return defaultModelNamespace ; } var trialModelNamespace = proposedModelNamespace . Replace ( " " , " " ) . Replace ( " " , " " ) . Replace ( " " , " " ) ; if ( ! EscherAttributeContentValidator . IsValidXmlAttributeValue ( trialModelNamespace ) || string . IsNullOrEmpty ( trialModelNamespace ) ) { return defaultModelNamespace ; } if ( IsValidModelNamespace ( trialModelNamespace ) ) { return trialModelNamespace ; } while ( trialModelNamespace . Length > 0 && ! Char . IsLetter ( trialModelNamespace [ 0 ] ) ) { trialModelNamespace = trialModelNamespace . Substring ( 1 ) ; } if ( String . IsNullOrEmpty ( trialModelNamespace ) ) { return defaultModelNamespace ; } if ( IsValidModelNamespace ( trialModelNamespace ) ) { return trialModelNamespace ; } trialModelNamespace += " " ; if ( IsValidModelNamespace ( trialModelNamespace ) ) { return trialModelNamespace ; } return defaultModelNamespace ; }
Returns a string which is valid as a model namespace given the
proposedModelNamespace as a starting point.
Returns a string which is valid as a model namespace given the proposedModelNamespace as a starting point .
// if trialModelNamespace is now valid just return it // if trialModelNamespace is invalid must be an invalid identifier // try stripping any leading numbers // try adding a one to the end // give up and return default
proposedModelNamespace
string
The proposed model namespace
The proposed model namespace
defaultModelNamespace
string
The model namespace to use if removal of invalid chars results in an empty string
The model namespace to use if removal of invalid chars results in an empty string