コード例 #1
0
        private static string NormalizeName(string name, bool fileSystemFriendly)
        {
            string str1 = name != null?name.Trim() : name;

            if (string.IsNullOrEmpty(str1))
            {
                return((string)null);
            }
            bool flag = true;

            for (int charIndex = 0; flag && charIndex < str1.Length; ++charIndex)
            {
                flag = SampleDataNameHelper.IsCharAllowed(str1[charIndex], charIndex);
            }
            if (flag)
            {
                if (!SampleDataNameHelper.IsXmlFriendly(str1))
                {
                    return((string)null);
                }
                if (fileSystemFriendly && PathHelper.IsDeviceName(str1))
                {
                    str1 = "_" + str1;
                }
                return(str1);
            }
            StringBuilder stringBuilder = new StringBuilder(str1.Length + 1);
            int           num           = 0;

            for (int charIndex = 0; charIndex < str1.Length; ++charIndex)
            {
                char c = str1[charIndex];
                if (!SampleDataNameHelper.IsCharAllowed(c, charIndex))
                {
                    c = '_';
                }
                else
                {
                    ++num;
                }
                stringBuilder.Append(c);
            }
            if (num == 0)
            {
                return((string)null);
            }
            string str2 = stringBuilder.ToString();

            if (fileSystemFriendly && PathHelper.IsDeviceName(str2))
            {
                str2 = "_" + str2;
            }
            if (!SampleDataNameHelper.IsXmlFriendly(str2))
            {
                str2 = (string)null;
            }
            return(str2);
        }
コード例 #2
0
        public static string GetSafeName(string name, IMSBuildProject msBuildProject, bool fileSystemFriendly)
        {
            string identifier = SampleDataNameHelper.NormalizeName(name, fileSystemFriendly);

            if (string.IsNullOrEmpty(identifier) || !msBuildProject.IsSafeIdentifier(identifier))
            {
                return((string)null);
            }
            return(identifier);
        }
コード例 #3
0
        public static string GetUniqueName(string name, IMSBuildProject msBuildProject, IEnumerable <string> existingNames, string nameToIgnore, bool fileSystemFriendly)
        {
            string str = SampleDataNameHelper.NormalizeName(name, fileSystemFriendly);

            if (string.IsNullOrEmpty(str) || !msBuildProject.IsSafeIdentifier(str))
            {
                return((string)null);
            }
            if (SampleDataNameHelper.IsUniqueAndSafeName(str, msBuildProject, existingNames, nameToIgnore, fileSystemFriendly))
            {
                return(str);
            }
            NumberedName numberedName = new NumberedName(str);

            while (numberedName.Increment())
            {
                string currentName = numberedName.CurrentName;
                if (SampleDataNameHelper.IsUniqueAndSafeName(currentName, msBuildProject, existingNames, nameToIgnore, fileSystemFriendly))
                {
                    return(currentName);
                }
            }
            return((string)null);
        }
コード例 #4
0
        public string GetUniqueSampleDataSetName(string name)
        {
            IEnumerable <string> existingNames = Enumerable.Select <SampleDataSet, string>((IEnumerable <SampleDataSet>) this.dataSets, (Func <SampleDataSet, string>)(dataSet => dataSet.Name));

            return(SampleDataNameHelper.GetUniqueName(name, this.msBuildProject, existingNames, (string)null, true));
        }