Skip to content

Commit

Permalink
Migrate to file-scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Jan 21, 2024
1 parent b40be21 commit 8dbb760
Show file tree
Hide file tree
Showing 95 changed files with 28,844 additions and 28,936 deletions.
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.NuGet.NuGetTasks;

[UnsetVisualStudioEnvironmentVariables]
partial class Build : NukeBuild
Expand Down
33 changes: 16 additions & 17 deletions docs/Build.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
namespace NetVips.Docs
{
using System;
using System.IO;
using System.Threading.Tasks;
using Docfx.Dotnet;
using System;
using System.IO;
using System.Threading.Tasks;
using Docfx.Dotnet;

namespace NetVips.Docs;

class Build
class Build
{
static async Task Main(string[] args)
{
static async Task Main(string[] args)
{
var projectDir =
Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\.."));
var currentDirectory = Directory.GetCurrentDirectory();
var projectDir =
Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\.."));
var currentDirectory = Directory.GetCurrentDirectory();

Directory.SetCurrentDirectory(projectDir);
await DotnetApiCatalog.GenerateManagedReferenceYamlFiles("docfx.json");
await Docfx.Docset.Build("docfx.json");
Directory.SetCurrentDirectory(currentDirectory);
}
Directory.SetCurrentDirectory(projectDir);
await DotnetApiCatalog.GenerateManagedReferenceYamlFiles("docfx.json");
await Docfx.Docset.Build("docfx.json");
Directory.SetCurrentDirectory(currentDirectory);
}
}
13 changes: 6 additions & 7 deletions samples/NetVips.Samples/ISample.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace NetVips
namespace NetVips;

public interface ISample
{
public interface ISample
{
string Name { get; }
string Name { get; }

string Category { get; }
string Category { get; }

void Execute(string[] args);
}
void Execute(string[] args);
}
157 changes: 78 additions & 79 deletions samples/NetVips.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,104 +1,103 @@
namespace NetVips
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace NetVips;

class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
private static readonly List<ISample> Samples = Assembly.GetExecutingAssembly().GetTypes()
.Where(x => x.GetInterfaces().Contains(typeof(ISample)) && x.GetConstructor(Type.EmptyTypes) != null)
.Select(x => Activator.CreateInstance(x) as ISample)
.OrderBy(s => s?.Category)
.ToList();

class Program
static void Main(string[] args)
{
private static readonly List<ISample> Samples = Assembly.GetExecutingAssembly().GetTypes()
.Where(x => x.GetInterfaces().Contains(typeof(ISample)) && x.GetConstructor(Type.EmptyTypes) != null)
.Select(x => Activator.CreateInstance(x) as ISample)
.OrderBy(s => s?.Category)
.ToList();

static void Main(string[] args)
if (!ModuleInitializer.VipsInitialized)
{
if (!ModuleInitializer.VipsInitialized)
{
Console.WriteLine("Error: Unable to init libvips. Please check your PATH environment variable.");
Console.ReadLine();
return;
}
Console.WriteLine("Error: Unable to init libvips. Please check your PATH environment variable.");
Console.ReadLine();
return;
}

Console.WriteLine($"libvips {NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}");
Console.WriteLine($"libvips {NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}");

Console.WriteLine(
$"Type a number (1-{Samples.Count}) to execute a sample of your choice. Press <Enter> or type 'Q' to quit.");
Console.WriteLine(
$"Type a number (1-{Samples.Count}) to execute a sample of your choice. Press <Enter> or type 'Q' to quit.");

DisplayMenu();
DisplayMenu();

string input;
do
string input;
do
{
var sampleArgs = Array.Empty<string>();
if (args.Length > 0)
{
var sampleArgs = Array.Empty<string>();
if (args.Length > 0)
{
var sampleId = Samples.Select((value, index) => new { Index = index + 1, value.Name })
.FirstOrDefault(s => s.Name.Equals(args[0]))?.Index;
input = sampleId != null ? $"{sampleId}" : "0";
sampleArgs = args.Skip(1).ToArray();
}
else
{
input = Console.ReadLine();
}
var sampleId = Samples.Select((value, index) => new { Index = index + 1, value.Name })
.FirstOrDefault(s => s.Name.Equals(args[0]))?.Index;
input = sampleId != null ? $"{sampleId}" : "0";
sampleArgs = args.Skip(1).ToArray();
}
else
{
input = Console.ReadLine();
}

if (int.TryParse(input, out var userChoice))
if (int.TryParse(input, out var userChoice))
{
if (!TryGetSample(userChoice, out var sample))
{
if (!TryGetSample(userChoice, out var sample))
{
Console.WriteLine("Sample doesn't exists, try again");
continue;
}

Console.WriteLine($"Executing sample: {sample.Name}");
sample.Execute(sampleArgs);
Console.WriteLine("Sample successfully executed!");
Console.WriteLine("Sample doesn't exists, try again");
continue;
}

// Clear any arguments
args = Array.Empty<string>();
} while (!string.IsNullOrEmpty(input) && !string.Equals(input, "Q", StringComparison.OrdinalIgnoreCase));
}
Console.WriteLine($"Executing sample: {sample.Name}");
sample.Execute(sampleArgs);
Console.WriteLine("Sample successfully executed!");
}

public static void DisplayMenu()
{
Console.WriteLine();
Console.WriteLine("Menu:");
// Clear any arguments
args = Array.Empty<string>();
} while (!string.IsNullOrEmpty(input) && !string.Equals(input, "Q", StringComparison.OrdinalIgnoreCase));
}

public static void DisplayMenu()
{
Console.WriteLine();
Console.WriteLine("Menu:");

string currCategory = null;
var menu = Samples.Select((value, index) => new { Index = index + 1, value.Name, value.Category })
.Aggregate(new StringBuilder(), (builder, pair) =>
string currCategory = null;
var menu = Samples.Select((value, index) => new { Index = index + 1, value.Name, value.Category })
.Aggregate(new StringBuilder(), (builder, pair) =>
{
if (currCategory != pair.Category)
{
if (currCategory != pair.Category)
if (pair.Index > 1)
{
if (pair.Index > 1)
{
builder.AppendLine();
}
builder.AppendLine();
}

builder.AppendLine($" - {pair.Category}");
builder.AppendLine($" - {pair.Category}");

currCategory = pair.Category;
}
currCategory = pair.Category;
}

builder.AppendLine($" {pair.Index}: {pair.Name}");
return builder;
});
builder.AppendLine($" {pair.Index}: {pair.Name}");
return builder;
});

Console.WriteLine(menu);
}
Console.WriteLine(menu);
}

public static bool TryGetSample(int id, out ISample sample)
{
sample = Samples
.Select((value, index) => new { Index = index + 1, Sample = value })
.FirstOrDefault(pair => pair.Index == id)?.Sample;
public static bool TryGetSample(int id, out ISample sample)
{
sample = Samples
.Select((value, index) => new { Index = index + 1, Sample = value })
.FirstOrDefault(pair => pair.Index == id)?.Sample;

return sample != null;
}
return sample != null;
}
}
99 changes: 49 additions & 50 deletions samples/NetVips.Samples/SampleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
namespace NetVips
{
using System;
using System.Linq;
using System;
using System.Linq;

namespace NetVips;

public static class SampleExtensions
public static class SampleExtensions
{
/// <summary>
/// Make first letter of a string upper case.
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new string with the first letter upper case.</returns>
internal static string FirstLetterToUpper(this string str)
{
/// <summary>
/// Make first letter of a string upper case.
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new string with the first letter upper case.</returns>
internal static string FirstLetterToUpper(this string str)
if (str == null)
{
if (str == null)
{
return null;
}

if (str.Length > 1)
{
return char.ToUpper(str[0]) + str[1..];
}

return str.ToUpper();
return null;
}

/// <summary>
/// Make first letter of a string lower case.
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new string with the first letter lower case.</returns>
internal static string FirstLetterToLower(this string str)
if (str.Length > 1)
{
if (str == null)
{
return null;
}

if (str.Length > 1)
{
return char.ToLower(str[0]) + str[1..];
}

return str.ToLower();
return char.ToUpper(str[0]) + str[1..];
}

/// <summary>
/// Convert snake case (my_string) to camel case (MyString).
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new camel cased string.</returns>
internal static string ToPascalCase(this string str)
return str.ToUpper();
}

/// <summary>
/// Make first letter of a string lower case.
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new string with the first letter lower case.</returns>
internal static string FirstLetterToLower(this string str)
{
if (str == null)
{
return str.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => char.ToUpperInvariant(s[0]) + s[1..])
.Aggregate(string.Empty, (s1, s2) => s1 + s2);
return null;
}

public static double NextDouble(this Random random, double minValue, double maxValue)
if (str.Length > 1)
{
return random.NextDouble() * (maxValue - minValue) + minValue;
return char.ToLower(str[0]) + str[1..];
}

return str.ToLower();
}

/// <summary>
/// Convert snake case (my_string) to camel case (MyString).
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>A new camel cased string.</returns>
internal static string ToPascalCase(this string str)
{
return str.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => char.ToUpperInvariant(s[0]) + s[1..])
.Aggregate(string.Empty, (s1, s2) => s1 + s2);
}

public static double NextDouble(this Random random, double minValue, double maxValue)
{
return random.NextDouble() * (maxValue - minValue) + minValue;
}
}
Loading

0 comments on commit 8dbb760

Please sign in to comment.