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); }
private static bool IsUniqueAndSafeName(string normalizedName, IMSBuildProject msBuildProject, IEnumerable <string> existingNames, string nameToIgnore, bool fileSystemFriendly) { if (!msBuildProject.IsSafeIdentifier(normalizedName) || fileSystemFriendly && PathHelper.IsDeviceName(normalizedName)) { return(false); } if (normalizedName == nameToIgnore) { return(true); } if (normalizedName == "xmlns") { return(false); } string normalizedName2 = (int)normalizedName[0] == 95 ? normalizedName.Substring(1) : (string)null; return(Enumerable.FirstOrDefault <string>(existingNames, (Func <string, bool>)(name => !(name == nameToIgnore) && (string.Compare(normalizedName, name, StringComparison.OrdinalIgnoreCase) == 0 || normalizedName2 != null && string.Compare(normalizedName2, name, StringComparison.OrdinalIgnoreCase) == 0))) == null); }
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); }