78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
using System.Text;
|
|
|
|
namespace LibraryVersionsGenerator;
|
|
|
|
internal abstract class CSharpFileBuilder
|
|
{
|
|
private bool _hasUsings = false;
|
|
|
|
internal StringBuilder Builder { get; } = new();
|
|
|
|
public CSharpFileBuilder AddAutoGeneratedHeader()
|
|
{
|
|
Builder.AppendLine(@"//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by the LibraryVersionsGenerator tool. To safely
|
|
// modify this file, edit PackageVersionDefinitions.cs and
|
|
// re-run the LibraryVersionsGenerator project in Visual Studio.
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost if
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
");
|
|
return this;
|
|
}
|
|
|
|
public virtual CSharpFileBuilder AddUsing(string usingNamespace)
|
|
{
|
|
_hasUsings = true;
|
|
|
|
Builder.AppendLine($"using {usingNamespace};");
|
|
|
|
return this;
|
|
}
|
|
|
|
public virtual CSharpFileBuilder BeginClass(string classNamespace, string className)
|
|
{
|
|
if (_hasUsings)
|
|
{
|
|
Builder.AppendLine();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(classNamespace))
|
|
{
|
|
Builder.AppendLine($"namespace {classNamespace};");
|
|
Builder.AppendLine();
|
|
}
|
|
|
|
Builder.AppendLine(@"public static partial class LibraryVersion
|
|
{");
|
|
|
|
return this;
|
|
}
|
|
|
|
public virtual CSharpFileBuilder EndClass()
|
|
{
|
|
Builder.AppendLine(@"}");
|
|
|
|
return this;
|
|
}
|
|
|
|
public abstract CSharpFileBuilder BeginTestPackage(string testApplicationName, string integrationName);
|
|
|
|
public abstract CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks, string[] supportedPlatforms);
|
|
|
|
public abstract CSharpFileBuilder AddVersionWithDependencies(string version, Dictionary<string, string> dependencies, string[] supportedFrameworks, string[] supportedPlatforms);
|
|
|
|
public abstract CSharpFileBuilder EndTestPackage();
|
|
|
|
public override string ToString()
|
|
{
|
|
return Builder.ToString();
|
|
}
|
|
}
|