Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatSelect - Adding support for GUID / GUID? #634

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/MatBlazor.Demo/Demo/DemoMatSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,47 @@
</SourceContent>
</DemoContainer>


<MatAnchorContainer Anchor="MatSelectInt">
<MatH5>MatSelect Guid?</MatH5>
</MatAnchorContainer>
<DemoContainer>
<Content>
<MatSelect Label="Pick a Food Group" @bind-Value="@guidValue">
<MatOption TValue="Guid?" Value="@(null)"></MatOption>
<MatOption TValue="Guid?" Value="@(new Guid("20A82054-F493-4C7B-81A4-4F9A1EDD7C2E"))">Bread, Cereal, Rice, and Pasta</MatOption>
<MatOption TValue="Guid?" Value="@(new Guid("4451642D-24F7-418F-8741-BA5089A1CC65"))">Vegetables</MatOption>
<MatOption TValue="Guid?" Value="@(new Guid("5717DBBE-C205-4E33-9E07-892A51F64021"))">Fruit</MatOption>
</MatSelect>

<span>@guidValue</span>

@code
{
Guid? guidValue = new Guid("20A82054-F493-4C7B-81A4-4F9A1EDD7C2E");
}

</Content>
<SourceContent>
<BlazorFiddle Template="MatBlazor" Code=@(@"
<MatSelect Label=""Pick a Food Group"" @bind-Value=""@guidValue"">
<MatOption TValue=""Guid?"" Value=""@(null)""></MatOption>
<MatOption TValue=""Guid?"" Value=""@(new Guid(""20A82054-F493-4C7B-81A4-4F9A1EDD7C2E""))"">Bread, Cereal, Rice, and Pasta</MatOption>
<MatOption TValue=""Guid?"" Value=""@(new Guid(""4451642D-24F7-418F-8741-BA5089A1CC65""))"">Vegetables</MatOption>
<MatOption TValue=""Guid?"" Value=""@(new Guid(""5717DBBE-C205-4E33-9E07-892A51F64021""))"">Fruit</MatOption>
</MatSelect>

<span>@guidValue</span>

@code
{
Guid? guidValue = new Guid(""20A82054-F493-4C7B-81A4-4F9A1EDD7C2E"");
}

")></BlazorFiddle>
</SourceContent>
</DemoContainer>

<h5 class="mat-h5">Helper Text</h5>
<DemoContainer>
<Content>
Expand Down
4 changes: 3 additions & 1 deletion src/MatBlazor/Core/MatBlazorSwitchT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public virtual T FromBool(bool v)
.Case<MatBlazorSwitchT<DateTime>>(new MatBlazorSwitchTDateTime())
.Case<MatBlazorSwitchT<DateTime?>>(new MatBlazorSwitchTDateTimeNull())
.Case<MatBlazorSwitchT<bool>>(new MatBlazorSwitchTBool())
.Case<MatBlazorSwitchT<bool?>>(new MatBlazorSwitchTBoolNull());
.Case<MatBlazorSwitchT<bool?>>(new MatBlazorSwitchTBoolNull())
.Case<MatBlazorSwitchT<Guid>>(new MatBlazorSwitchTGuid())
.Case<MatBlazorSwitchT<Guid?>>(new MatBlazorSwitchTGuidNull());

public static MatBlazorSwitchT<T> Get()
{
Expand Down
67 changes: 67 additions & 0 deletions src/MatBlazor/Core/MatBlazorSwitchTGuid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;

namespace MatBlazor
{
public class MatBlazorSwitchTGuid : MatBlazorSwitchT<Guid>
{
public override Guid Increase(Guid v, Guid step, Guid max)
{
throw new NotImplementedException();
}

public override Guid Decrease(Guid v, Guid step, Guid min)
{
throw new NotImplementedException();
}

public override Guid Round(Guid v, int dp)
{
throw new NotImplementedException();
}

public override Guid GetMinimum()
{
throw new NotImplementedException();
}

public override Guid GetMaximum()
{
throw new NotImplementedException();
}

public override Guid GetStep()
{
throw new NotImplementedException();
}

public override string FormatValueAsString(Guid v, string format)
{
return v.ToString(format);
}

public override Guid ParseFromString(string v, string format)
{
return Guid.Parse(v);
}

public override Guid FromDateTimeNull(DateTime? v)
{
throw new NotImplementedException();
}

public override DateTime? ToDateTimeNull(Guid v)
{
throw new NotImplementedException();
}

public override Guid FromBoolNull(bool? v, bool indeterminate)
{
throw new NotImplementedException();
}

public override Guid FromDecimal(decimal v)
{
throw new NotImplementedException();
}
}
}
72 changes: 72 additions & 0 deletions src/MatBlazor/Core/MatBlazorSwitchTGuidNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;

namespace MatBlazor
{
public class MatBlazorSwitchTGuidNull : MatBlazorSwitchT<Guid?>
{
public override Guid? Increase(Guid? v, Guid? step, Guid? max)
{
throw new NotImplementedException();
}

public override Guid? Decrease(Guid? v, Guid? step, Guid? min)
{
throw new NotImplementedException();
}

public override Guid? Round(Guid? v, int dp)
{
throw new NotImplementedException();
}

public override Guid? GetMinimum()
{
throw new NotImplementedException();
}

public override Guid? GetMaximum()
{
throw new NotImplementedException();
}

public override Guid? GetStep()
{
throw new NotImplementedException();
}

public override string FormatValueAsString(Guid? v, string format)
{
return v?.ToString(format);
}

public override Guid? ParseFromString(string v, string format)
{
if (Guid.TryParse(v, out var result))
{
return result;
}

return null;
}

public override Guid? FromDateTimeNull(DateTime? v)
{
throw new NotImplementedException();
}

public override DateTime? ToDateTimeNull(Guid? v)
{
throw new NotImplementedException();
}

public override Guid? FromBoolNull(bool? v, bool indeterminate)
{
throw new NotImplementedException();
}

public override Guid? FromDecimal(decimal v)
{
throw new NotImplementedException();
}
}
}