Skip to content

Commit

Permalink
Merge pull request #21 from fnajera-rac-de/default-value-raw
Browse files Browse the repository at this point in the history
Default value raw
  • Loading branch information
rrmanzano authored Dec 20, 2023
2 parents c76122a + db25149 commit 418ede6
Show file tree
Hide file tree
Showing 27 changed files with 320 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,32 @@ public Task Create_With_DefaultValue_As_String()
return Build(definition);
}

[Fact]
public Task Create_With_DefaultValue_As_String_Code()
{
var definition = """
private static string MyDefaultValue = "my default value goes here";

[AutoBindable(DefaultValue = "\" + MyDefaultValue + \"")]
private readonly string _country;
""";

return Build(definition);
}

[Fact]
public Task Create_With_DefaultValueRaw_As_String()
{
var definition = """
private static string MyDefaultValue = "my default value goes here";

[AutoBindable(DefaultValueRaw = "MyDefaultValue")]
private readonly string _country;
""";

return Build(definition);
}

[Fact]
public Task Create_With_ValidateValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//HintName: AutoBindableAttribute.cs

#pragma warning disable
#nullable enable
using System;
namespace Maui.BindableProperty.Generator.Core
{
public enum BindablePropertyAccessibility
{
/// <summary>
/// If 'Undefined', bindable property will be defined in the same way as the class that contains it.
/// </summary>
Undefined = 0,

/// <summary>
/// Bindable property will be defined as 'private'
/// </summary>
Private = 1,

/// <summary>
/// Bindable property will be defined as 'private protected'
/// </summary>
ProtectedAndInternal = 2,

/// <summary>
/// Bindable property will be defined as 'protected'
/// </summary>
Protected = 3,

/// <summary>
/// Bindable property will be defined as 'internal'
/// </summary>
Internal = 4,

/// <summary>
/// Bindable property will be defined as 'protected internal'
/// </summary>
ProtectedOrInternal = 5,

/// <summary>
/// Bindable property will be defined as 'public'
/// </summary>
Public = 6
}

[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
[System.Diagnostics.Conditional("AutoBindableGenerator_DEBUG")]
public sealed class AutoBindableAttribute : Attribute
{
public AutoBindableAttribute(){}

public string PropertyName { get; set; } = string.Empty;

public string? OnChanged { get; set; }

public string? OnChanging { get; set; }

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }

public bool HidesUnderlyingProperty { get; set; } = false;

public BindablePropertyAccessibility PropertyAccessibility { get; set; } = BindablePropertyAccessibility.Undefined;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//HintName: HeaderControl.generated.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace Maui.BindableProperty.Generator.Demo.CustomControls
{
public partial class HeaderControl
{
/// <inheritdoc cref="_country"/>
[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
public static readonly Microsoft.Maui.Controls.BindableProperty CountryProperty =
Microsoft.Maui.Controls.BindableProperty.Create(
nameof(Country),
typeof(string),
typeof(HeaderControl),
defaultValue: MyDefaultValue,
propertyChanged: __CountryChanged,
propertyChanging: __CountryChanging);

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public string Country
{
get => (string)GetValue(CountryProperty);
set => SetValue(CountryProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private static void __CountryChanged(Microsoft.Maui.Controls.BindableObject bindable, object oldValue, object newValue)
{
var ctrl = (global::Maui.BindableProperty.Generator.Demo.CustomControls.HeaderControl)bindable;
ctrl.OnCountryChanged((string)newValue);
}

partial void OnCountryChanged(string value);

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private static void __CountryChanging(Microsoft.Maui.Controls.BindableObject bindable, object oldValue, object newValue)
{
var ctrl = (global::Maui.BindableProperty.Generator.Demo.CustomControls.HeaderControl)bindable;
ctrl.OnCountryChanging((string)oldValue);
}

partial void OnCountryChanging(string value);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//HintName: AutoBindableAttribute.cs

#pragma warning disable
#nullable enable
using System;
namespace Maui.BindableProperty.Generator.Core
{
public enum BindablePropertyAccessibility
{
/// <summary>
/// If 'Undefined', bindable property will be defined in the same way as the class that contains it.
/// </summary>
Undefined = 0,

/// <summary>
/// Bindable property will be defined as 'private'
/// </summary>
Private = 1,

/// <summary>
/// Bindable property will be defined as 'private protected'
/// </summary>
ProtectedAndInternal = 2,

/// <summary>
/// Bindable property will be defined as 'protected'
/// </summary>
Protected = 3,

/// <summary>
/// Bindable property will be defined as 'internal'
/// </summary>
Internal = 4,

/// <summary>
/// Bindable property will be defined as 'protected internal'
/// </summary>
ProtectedOrInternal = 5,

/// <summary>
/// Bindable property will be defined as 'public'
/// </summary>
Public = 6
}

[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
[System.Diagnostics.Conditional("AutoBindableGenerator_DEBUG")]
public sealed class AutoBindableAttribute : Attribute
{
public AutoBindableAttribute(){}

public string PropertyName { get; set; } = string.Empty;

public string? OnChanged { get; set; }

public string? OnChanging { get; set; }

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }

public bool HidesUnderlyingProperty { get; set; } = false;

public BindablePropertyAccessibility PropertyAccessibility { get; set; } = BindablePropertyAccessibility.Undefined;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//HintName: HeaderControl.generated.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace Maui.BindableProperty.Generator.Demo.CustomControls
{
public partial class HeaderControl
{
/// <inheritdoc cref="_country"/>
[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
public static readonly Microsoft.Maui.Controls.BindableProperty CountryProperty =
Microsoft.Maui.Controls.BindableProperty.Create(
nameof(Country),
typeof(string),
typeof(HeaderControl),
defaultValue: "" + MyDefaultValue + "",
propertyChanged: __CountryChanged,
propertyChanging: __CountryChanging);

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public string Country
{
get => (string)GetValue(CountryProperty);
set => SetValue(CountryProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private static void __CountryChanged(Microsoft.Maui.Controls.BindableObject bindable, object oldValue, object newValue)
{
var ctrl = (global::Maui.BindableProperty.Generator.Demo.CustomControls.HeaderControl)bindable;
ctrl.OnCountryChanged((string)newValue);
}

partial void OnCountryChanged(string value);

[global::System.CodeDom.Compiler.GeneratedCode("Maui.BindableProperty.Generator.Core.BindableProperty.AutoBindablePropertyGenerator", "0.11.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private static void __CountryChanging(Microsoft.Maui.Controls.BindableObject bindable, object oldValue, object newValue)
{
var ctrl = (global::Maui.BindableProperty.Generator.Demo.CustomControls.HeaderControl)bindable;
ctrl.OnCountryChanging((string)oldValue);
}

partial void OnCountryChanging(string value);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public AutoBindableAttribute(){}

public string? DefaultValue { get; set; }

public string? DefaultValueRaw { get; set; }

public string? DefaultBindingMode { get; set; }

public string? ValidateValue { get; set; }
Expand Down
Loading

0 comments on commit 418ede6

Please sign in to comment.