private static bool IsGeneratedCodeFile([NotNullWhen(returnValue: true)] string?filePath) { if (!RoslynString.IsNullOrEmpty(filePath)) { var fileName = PathUtilities.GetFileName(filePath); if (fileName.StartsWith("TemporaryGeneratedFile_", StringComparison.OrdinalIgnoreCase)) { return(true); } var extension = PathUtilities.GetExtension(fileName); if (!string.IsNullOrEmpty(extension)) { var fileNameWithoutExtension = PathUtilities.GetFileName(filePath, includeExtension: false); if (fileNameWithoutExtension.EndsWith(".designer", StringComparison.OrdinalIgnoreCase) || fileNameWithoutExtension.EndsWith(".generated", StringComparison.OrdinalIgnoreCase) || fileNameWithoutExtension.EndsWith(".g", StringComparison.OrdinalIgnoreCase) || fileNameWithoutExtension.EndsWith(".g.i", StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }
/// <summary> /// Parse the value provided to an MSBuild Feature option into a list of entries. This will /// leave name=value in their raw form. /// </summary> public static IList <string> ParseFeatureFromMSBuild(string?features) { if (RoslynString.IsNullOrEmpty(features)) { return(new List <string>(capacity: 0)); } return(features.Split(new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); }
/// <summary> /// Checks if the given name is a sequence of valid CLR names separated by a dot. /// </summary> internal static bool IsValidClrNamespaceName([NotNullWhen(returnValue: true)] this string?name) { if (RoslynString.IsNullOrEmpty(name)) { return(false); } char lastChar = '.'; foreach (char c in name) { if (c == '\0' || (c == '.' && lastChar == '.')) { return(false); } lastChar = c; } return(lastChar != '.'); }
private static string?ConvertCase( this string?shortName, bool trimLeadingTypePrefix, Func <char, char> convert) { // Special case the common .NET pattern of "IGoo" as a type name. In this case we // want to generate "goo" as the parameter name. if (!RoslynString.IsNullOrEmpty(shortName)) { if (trimLeadingTypePrefix && (shortName.LooksLikeInterfaceName() || shortName.LooksLikeTypeParameterName())) { return(convert(shortName[1]) + shortName.Substring(2)); } if (convert(shortName[0]) != shortName[0]) { return(convert(shortName[0]) + shortName.Substring(1)); } } return(shortName); }
/// <summary> /// Check that the name is a valid Unicode identifier. /// </summary> public static bool IsValidIdentifier([NotNullWhen(returnValue: true)] string?name) { if (RoslynString.IsNullOrEmpty(name)) { return(false); } if (!IsIdentifierStartCharacter(name[0])) { return(false); } int nameLength = name.Length; for (int i = 1; i < nameLength; i++) //NB: start at 1 { if (!IsIdentifierPartCharacter(name[i])) { return(false); } } return(true); }
internal static bool IsValidClrTypeName([NotNullWhen(returnValue: true)] this string?name) { return(!RoslynString.IsNullOrEmpty(name) && name.IndexOf('\0') == -1); }
// String escaping implementation forked from System.Runtime.Serialization.Json to // avoid a large dependency graph for this small amount of code: // // https://github.com/dotnet/corefx/blob/master/src/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JavaScriptString.cs // private static string EscapeString(string?value) { PooledStringBuilder?pooledBuilder = null; StringBuilder? b = null; if (RoslynString.IsNullOrEmpty(value)) { return(string.Empty); } int startIndex = 0; int count = 0; for (int i = 0; i < value.Length; i++) { char c = value[i]; if (c == '\"' || c == '\\' || ShouldAppendAsUnicode(c)) { if (b == null) { RoslynDebug.Assert(pooledBuilder == null); pooledBuilder = PooledStringBuilder.GetInstance(); b = pooledBuilder.Builder; } if (count > 0) { b.Append(value, startIndex, count); } startIndex = i + 1; count = 0; switch (c) { case '\"': b.Append("\\\""); break; case '\\': b.Append("\\\\"); break; default: RoslynDebug.Assert(ShouldAppendAsUnicode(c)); AppendCharAsUnicode(b, c); break; } } else { count++; } } if (b == null) { return(value); } else { RoslynDebug.Assert(pooledBuilder is object); } if (count > 0) { b.Append(value, startIndex, count); } return(pooledBuilder.ToStringAndFree()); }