This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use file scoped namespaces (#75)
* Use file scoped namespaces everywhere * Use .NET 6
- Loading branch information
1 parent
c2c394b
commit cb79cd8
Showing
38 changed files
with
1,212 additions
and
1,151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.NameGenerator.Sandbox.ViewModels; | ||
using Avalonia.NameGenerator.Sandbox.Views; | ||
|
||
namespace Avalonia.NameGenerator.Sandbox | ||
namespace Avalonia.NameGenerator.Sandbox; | ||
|
||
public class App : Application | ||
{ | ||
public class App : Application | ||
{ | ||
public override void Initialize() => AvaloniaXamlLoader.Load(this); | ||
public override void Initialize() => AvaloniaXamlLoader.Load(this); | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
var view = new SignUpView | ||
{ | ||
var view = new SignUpView(); | ||
view.Show(); | ||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
ViewModel = new SignUpViewModel() | ||
}; | ||
view.Show(); | ||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
using System; | ||
using Avalonia.Controls; | ||
using Avalonia.Styling; | ||
|
||
namespace Avalonia.NameGenerator.Sandbox.Controls | ||
namespace Avalonia.NameGenerator.Sandbox.Controls; | ||
|
||
public class CustomTextBox : TextBox, IStyleable | ||
{ | ||
public class CustomTextBox : TextBox { } | ||
Type IStyleable.StyleKey => typeof(TextBox); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using Avalonia.ReactiveUI; | ||
|
||
namespace Avalonia.NameGenerator.Sandbox | ||
namespace Avalonia.NameGenerator.Sandbox; | ||
|
||
internal static class Program | ||
{ | ||
internal static class Program | ||
{ | ||
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); | ||
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); | ||
|
||
private static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure<App>() | ||
.UseReactiveUI() | ||
.UsePlatformDetect() | ||
.LogToTrace(); | ||
} | ||
private static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure<App>() | ||
.UseReactiveUI() | ||
.UsePlatformDetect() | ||
.LogToTrace(); | ||
} |
70 changes: 70 additions & 0 deletions
70
src/Avalonia.NameGenerator.Sandbox/ViewModels/SignUpViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Reactive; | ||
using ReactiveUI; | ||
using ReactiveUI.Validation.Extensions; | ||
using ReactiveUI.Validation.Helpers; | ||
|
||
namespace Avalonia.NameGenerator.Sandbox.ViewModels; | ||
|
||
public class SignUpViewModel : ReactiveValidationObject | ||
{ | ||
private string _userName = string.Empty; | ||
private string _password = string.Empty; | ||
private string _confirmPassword = string.Empty; | ||
|
||
public SignUpViewModel() | ||
{ | ||
this.ValidationRule( | ||
vm => vm.UserName, | ||
name => !string.IsNullOrWhiteSpace(name), | ||
"UserName is required."); | ||
|
||
this.ValidationRule( | ||
vm => vm.Password, | ||
password => !string.IsNullOrWhiteSpace(password), | ||
"Password is required."); | ||
|
||
this.ValidationRule( | ||
vm => vm.Password, | ||
password => password?.Length > 2, | ||
password => $"Password should be longer, current length: {password.Length}"); | ||
|
||
this.ValidationRule( | ||
vm => vm.ConfirmPassword, | ||
confirmation => !string.IsNullOrWhiteSpace(confirmation), | ||
"Confirm password field is required."); | ||
|
||
var passwordsObservable = | ||
this.WhenAnyValue( | ||
x => x.Password, | ||
x => x.ConfirmPassword, | ||
(password, confirmation) => | ||
password == confirmation); | ||
|
||
this.ValidationRule( | ||
vm => vm.ConfirmPassword, | ||
passwordsObservable, | ||
"Passwords must match."); | ||
|
||
SignUp = ReactiveCommand.Create(() => {}, this.IsValid()); | ||
} | ||
|
||
public ReactiveCommand<Unit, Unit> SignUp { get; } | ||
|
||
public string UserName | ||
{ | ||
get => _userName; | ||
set => this.RaiseAndSetIfChanged(ref _userName, value); | ||
} | ||
|
||
public string Password | ||
{ | ||
get => _password; | ||
set => this.RaiseAndSetIfChanged(ref _password, value); | ||
} | ||
|
||
public string ConfirmPassword | ||
{ | ||
get => _confirmPassword; | ||
set => this.RaiseAndSetIfChanged(ref _confirmPassword, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 46 additions & 21 deletions
67
src/Avalonia.NameGenerator.Sandbox/Views/SignUpView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
using Avalonia.Controls; | ||
using System; | ||
using System.Reactive.Disposables; | ||
using Avalonia.NameGenerator.Sandbox.ViewModels; | ||
using Avalonia.ReactiveUI; | ||
using ReactiveUI; | ||
using ReactiveUI.Validation.Extensions; | ||
using ReactiveUI.Validation.Formatters; | ||
|
||
namespace Avalonia.NameGenerator.Sandbox.Views | ||
namespace Avalonia.NameGenerator.Sandbox.Views; | ||
|
||
/// <summary> | ||
/// This is a sample view class with typed x:Name references generated using | ||
/// .NET 5 source generators. The class has to be partial because x:Name | ||
/// references are living in a separate partial class file. See also: | ||
/// https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/ | ||
/// </summary> | ||
public partial class SignUpView : ReactiveWindow<SignUpViewModel> | ||
{ | ||
/// <summary> | ||
/// This is a sample view class with typed x:Name references generated at compile-time using | ||
/// .NET 5 source generators. The class should be marked with [GenerateTypedNameReferences], | ||
/// this attribute is also compile-time generated. The class has to be partial because x:Name | ||
/// references are living in a separate partial class file. See also: | ||
/// https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/ | ||
/// </summary> | ||
public partial class SignUpView : Window | ||
public SignUpView() | ||
{ | ||
public SignUpView() | ||
// The InitializeComponent method is also generated automatically | ||
// and lives in the autogenerated part of the partial class. | ||
InitializeComponent(); | ||
this.WhenActivated(disposables => | ||
{ | ||
InitializeComponent(); | ||
this.Bind(ViewModel, x => x.UserName, x => x.UserNameTextBox.Text) | ||
.DisposeWith(disposables); | ||
this.Bind(ViewModel, x => x.Password, x => x.PasswordTextBox.Text) | ||
.DisposeWith(disposables); | ||
this.Bind(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordTextBox.Text) | ||
.DisposeWith(disposables); | ||
this.BindCommand(ViewModel, x => x.SignUp, x => x.SignUpButton) | ||
.DisposeWith(disposables); | ||
|
||
this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text) | ||
.DisposeWith(disposables); | ||
this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text) | ||
.DisposeWith(disposables); | ||
this.BindValidation(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordValidation.Text) | ||
.DisposeWith(disposables); | ||
|
||
var newLineFormatter = new SingleLineFormatter(Environment.NewLine); | ||
this.BindValidation(ViewModel, x => x.CompoundValidation.Text, newLineFormatter) | ||
.DisposeWith(disposables); | ||
|
||
// The references to text boxes below are also auto generated. | ||
// Use Ctrl+Click in order to view the generated sources. | ||
UserNameTextBox.Text = "Joseph!"; | ||
UserNameValidation.Text = "User name is valid."; | ||
PasswordTextBox.Text = "qwerty"; | ||
PasswordValidation.Text = "Password is valid."; | ||
ConfirmPasswordTextBox.Text = "qwerty"; | ||
ConfirmPasswordValidation.Text = "Password confirmation is valid."; | ||
SignUpButton.Content = "Sign up please!"; | ||
CompoundValidation.Text = "Everything is okay."; | ||
AwesomeListView.VirtualizationMode = ItemVirtualizationMode.None; | ||
} | ||
PasswordTextBox.Text = "1234"; | ||
ConfirmPasswordTextBox.Text = "1234"; | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Avalonia.NameGenerator.Tests/Avalonia.NameGenerator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
using Avalonia.NameGenerator.Generator; | ||
using Xunit; | ||
|
||
namespace Avalonia.NameGenerator.Tests | ||
namespace Avalonia.NameGenerator.Tests; | ||
|
||
public class GlobPatternTests | ||
{ | ||
public class GlobPatternTests | ||
[Theory] | ||
[InlineData("*", "anything", true)] | ||
[InlineData("", "anything", false)] | ||
[InlineData("Views/*", "Views/SignUpView.xaml", true)] | ||
[InlineData("Views/*", "Extensions/SignUpView.xaml", false)] | ||
[InlineData("*SignUpView*", "Extensions/SignUpView.xaml", true)] | ||
[InlineData("*SignUpView.paml", "Extensions/SignUpView.xaml", false)] | ||
[InlineData("*.xaml", "Extensions/SignUpView.xaml", true)] | ||
public void Should_Match_Glob_Expressions(string pattern, string value, bool matches) | ||
{ | ||
[Theory] | ||
[InlineData("*", "anything", true)] | ||
[InlineData("", "anything", false)] | ||
[InlineData("Views/*", "Views/SignUpView.xaml", true)] | ||
[InlineData("Views/*", "Extensions/SignUpView.xaml", false)] | ||
[InlineData("*SignUpView*", "Extensions/SignUpView.xaml", true)] | ||
[InlineData("*SignUpView.paml", "Extensions/SignUpView.xaml", false)] | ||
[InlineData("*.xaml", "Extensions/SignUpView.xaml", true)] | ||
public void Should_Match_Glob_Expressions(string pattern, string value, bool matches) | ||
{ | ||
Assert.Equal(matches, new GlobPattern(pattern).Matches(value)); | ||
} | ||
Assert.Equal(matches, new GlobPattern(pattern).Matches(value)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Views/SignUpView.xaml", true, new[] { "*.xaml", "Extensions/*" })] | ||
[InlineData("Extensions/SignUpView.paml", true, new[] { "*.xaml", "Extensions/*" })] | ||
[InlineData("Extensions/SignUpView.paml", false, new[] { "*.xaml", "Views/*" })] | ||
[InlineData("anything", true, new[] { "*", "*" })] | ||
[InlineData("anything", false, new[] { "", "" })] | ||
public void Should_Match_Glob_Pattern_Groups(string value, bool matches, string[] patterns) | ||
{ | ||
Assert.Equal(matches, new GlobPatternGroup(patterns).Matches(value)); | ||
} | ||
[Theory] | ||
[InlineData("Views/SignUpView.xaml", true, new[] { "*.xaml", "Extensions/*" })] | ||
[InlineData("Extensions/SignUpView.paml", true, new[] { "*.xaml", "Extensions/*" })] | ||
[InlineData("Extensions/SignUpView.paml", false, new[] { "*.xaml", "Views/*" })] | ||
[InlineData("anything", true, new[] { "*", "*" })] | ||
[InlineData("anything", false, new[] { "", "" })] | ||
public void Should_Match_Glob_Pattern_Groups(string value, bool matches, string[] patterns) | ||
{ | ||
Assert.Equal(matches, new GlobPatternGroup(patterns).Matches(value)); | ||
} | ||
} |
Oops, something went wrong.