/// <summary> /// Generate the `Image.Generated.cs` file. /// </summary> /// <remarks> /// This is used to generate the `Image.Generated.cs` file (<see cref="Image"/>). /// </remarks> /// <param name="indent">Indentation level.</param> /// <returns>The `Image.Generated.cs` as string.</returns> private string Generate(string indent = " ") { // get the list of all nicknames we can generate docstrings for. var allNickNames = NetVips.GetOperations(); // remove operations we have to wrap by hand var exclude = new[] { "scale", "ifthenelse", "bandjoin", "bandrank", "composite", "case" }; allNickNames = allNickNames.Where(x => !exclude.Contains(x)).ToList(); const string preamble = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // libvips version: {0} // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------"; var stringBuilder = new StringBuilder(string.Format(preamble, $"{NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}")); stringBuilder.AppendLine() .AppendLine() .AppendLine("namespace NetVips") .AppendLine("{") .AppendLine(" public sealed partial class Image") .AppendLine(" {") .AppendLine($"{indent}#region auto-generated functions") .AppendLine(); foreach (var nickname in allNickNames) { try { stringBuilder.AppendLine(GenerateFunction(nickname, indent)); } catch (Exception e) { Console.WriteLine(e.Message); } } stringBuilder.AppendLine($"{indent}#endregion") .AppendLine() .AppendLine($"{indent}#region auto-generated properties") .AppendLine(); var tmpFile = Image.NewTempFile("%s.v"); var allProperties = tmpFile.GetFields(); foreach (var property in allProperties) { var type = GTypeToCSharp(tmpFile.GetTypeOf(property)); stringBuilder.AppendLine($"{indent}/// <summary>") .AppendLine($"{indent}/// {tmpFile.GetBlurb(property)}") .AppendLine($"{indent}/// </summary>") .AppendLine($"{indent}public {type} {property.ToPascalCase()} => ({type})Get(\"{property}\");") .AppendLine(); } stringBuilder.AppendLine($"{indent}#endregion") .AppendLine(" }") .AppendLine("}"); return(stringBuilder.ToString()); }
/// <summary> /// Generate the `Enums.Generated.cs` file. /// </summary> /// <remarks> /// This is used to generate the `Enums.Generated.cs` file (<see cref="Enums"/>). /// </remarks> /// <returns>The `Enums.Generated.cs` as string.</returns> private string Generate() { // otherwise we're missing some enums SaveableGetType(); var _ = Image.Black(1, 1); var allEnums = NetVips.GetEnums(); const string preamble = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // libvips version: {0} // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------"; var stringBuilder = new StringBuilder(string.Format(preamble, $"{NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}")); stringBuilder.AppendLine() .AppendLine() .AppendLine("namespace NetVips") .AppendLine("{") .AppendLine(" using System;") .AppendLine() .AppendLine(" public partial static class Enums") .AppendLine(" {") .AppendLine(" #region auto-generated enums") .AppendLine(); foreach (var name in allEnums) { if (name.StartsWith("Gsf")) { continue; } var gtype = NetVips.TypeFromName(name); var csharpName = RemovePrefix(name); stringBuilder.AppendLine(" /// <summary>") .AppendLine($" /// {csharpName}") .AppendLine(" /// </summary>") .AppendLine($" public static class {csharpName}") .AppendLine(" {"); var enumValues = NetVips.ValuesForEnum(gtype); for (var i = 0; i < enumValues.Count; i++) { var value = enumValues[i]; var csharpValue = value.Replace('-', '_').ToPascalCase(); stringBuilder.AppendLine($" /// <summary>{csharpValue}</summary>") .AppendLine($" public const string {csharpValue} = \"{value}\";"); if (i != enumValues.Count - 1) { stringBuilder.AppendLine(); } } stringBuilder.AppendLine(" }").AppendLine(); } stringBuilder.AppendLine(" #endregion") .AppendLine(" }") .AppendLine("}"); return(stringBuilder.ToString()); }