public static string Generate(AssemblyInfoOptions metadata, IEnumerable <string> sourceFiles) { var projectAttributes = GetProjectAttributes(metadata); var existingAttributes = new List <Type>(); foreach (var sourceFile in sourceFiles) { var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile)); var root = tree.GetRoot(); // assembly attributes can be only on first level foreach (var attributeListSyntax in root.ChildNodes().OfType <AttributeListSyntax>()) { if (attributeListSyntax.Target.Identifier.Kind() == SyntaxKind.AssemblyKeyword) { foreach (var attributeSyntax in attributeListSyntax.Attributes) { var projectAttribute = projectAttributes.FirstOrDefault(attribute => IsSameAttribute(attribute.Key, attributeSyntax)); if (projectAttribute.Key != null) { existingAttributes.Add(projectAttribute.Key); } } } } } return(string.Join(Environment.NewLine, projectAttributes .Where(projectAttribute => projectAttribute.Value != null && !existingAttributes.Contains(projectAttribute.Key)) .Select(projectAttribute => $"[assembly:{projectAttribute.Key.FullName}(\"{projectAttribute.Value}\")]"))); }
public static string GenerateFSharp(AssemblyInfoOptions metadata) { var projectAttributes = GetProjectAttributes(metadata); return(string.Join(Environment.NewLine, new[] { "namespace System", Environment.NewLine, Environment.NewLine } .Concat(projectAttributes.Select(projectAttribute => $"[<assembly:{projectAttribute.Key.FullName}(\"{projectAttribute.Value}\")>]")) .Concat(new[] { "do ()", Environment.NewLine }))); }
private static Dictionary <Type, string> GetProjectAttributes(AssemblyInfoOptions metadata) { return(new Dictionary <Type, string>() { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), [typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description), [typeof(AssemblyCopyrightAttribute)] = EscapeCharacters(metadata.Copyright), [typeof(AssemblyFileVersionAttribute)] = EscapeCharacters(metadata.AssemblyFileVersion?.ToString()), [typeof(AssemblyVersionAttribute)] = EscapeCharacters(metadata.AssemblyVersion?.ToString()), [typeof(AssemblyInformationalVersionAttribute)] = EscapeCharacters(metadata.InformationalVersion), [typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture), [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage), [typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework) }); }
public static string Generate(AssemblyInfoOptions metadata, IEnumerable <string> sourceFiles) { var projectAttributes = new Dictionary <Type, string>() { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), [typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description), [typeof(AssemblyCopyrightAttribute)] = EscapeCharacters(metadata.Copyright), [typeof(AssemblyFileVersionAttribute)] = EscapeCharacters(metadata.AssemblyFileVersion?.ToString()), [typeof(AssemblyVersionAttribute)] = EscapeCharacters(metadata.AssemblyVersion?.ToString()), [typeof(AssemblyInformationalVersionAttribute)] = EscapeCharacters(metadata.InformationalVersion), [typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture), [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage), [typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework) }; var existingAttributes = new List <Type>(); foreach (var sourceFile in sourceFiles) { var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile)); var root = tree.GetRoot(); // assembly attributes can be only on first level foreach (var attributeListSyntax in root.ChildNodes().OfType <AttributeListSyntax>()) { if (attributeListSyntax.Target.Identifier.Kind() == SyntaxKind.AssemblyKeyword) { foreach (var attributeSyntax in attributeListSyntax.Attributes) { var projectAttribute = projectAttributes.FirstOrDefault(attribute => IsSameAttribute(attribute.Key, attributeSyntax)); if (projectAttribute.Key != null) { existingAttributes.Add(projectAttribute.Key); } } } } } return(string.Join(Environment.NewLine, projectAttributes .Where(projectAttribute => projectAttribute.Value != null && !existingAttributes.Contains(projectAttribute.Key)) .Select(projectAttribute => $"[assembly:{projectAttribute.Key.FullName}(\"{projectAttribute.Value}\")]"))); }
public static IEnumerable <string> SerializeToArgs(AssemblyInfoOptions assemblyInfoOptions) { var options = new List <string>(); if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.Title)) { options.Add(FormatOption(TitleOptionName, assemblyInfoOptions.Title)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.Description)) { options.Add(FormatOption(DescriptionOptionName, assemblyInfoOptions.Description)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.Copyright)) { options.Add(FormatOption(CopyrightOptionName, assemblyInfoOptions.Copyright)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.AssemblyFileVersion)) { options.Add(FormatOption(AssemblyFileVersionOptionName, assemblyInfoOptions.AssemblyFileVersion)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.AssemblyVersion)) { options.Add(FormatOption(AssemblyVersionOptionName, assemblyInfoOptions.AssemblyVersion)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.InformationalVersion)) { options.Add(FormatOption(InformationalVersionOptionName, assemblyInfoOptions.InformationalVersion)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.Culture)) { options.Add(FormatOption(CultureOptionName, assemblyInfoOptions.Culture)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.NeutralLanguage)) { options.Add(FormatOption(NeutralCultureOptionName, assemblyInfoOptions.NeutralLanguage)); } if (!string.IsNullOrWhiteSpace(assemblyInfoOptions.TargetFramework)) { options.Add(FormatOption(TargetFrameworkOptionName, assemblyInfoOptions.TargetFramework)); } return(options); }