Skip to content

Commit

Permalink
Merge pull request #634 from softwaretirol/feature/GuidAndNullableGui…
Browse files Browse the repository at this point in the history
…dSelect

MatSelect - Adding support for GUID / GUID?
  • Loading branch information
enkodellc committed Jul 3, 2020
2 parents feaa44c + 6359c57 commit b5c707c
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 1 deletion.
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();
}
}
}

0 comments on commit b5c707c

Please sign in to comment.