Skip to content

Commit

Permalink
Added adapters for converting between ints and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryDungan committed Jul 4, 2017
1 parent 1e59c45 commit 97c4b44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions UnityWeld/Binding/Adapters/IntToStringAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace UnityWeld.Binding.Adapters
{
/// <summary>
/// Adapter for converting from an int to a string.
/// </summary>
[Adapter(typeof(int), typeof(string))]
public class IntToStringAdapter : IAdapter
{
public object Convert(object valueIn, AdapterOptions options)
{
return ((int)valueIn).ToString();
}
}
}
14 changes: 14 additions & 0 deletions UnityWeld/Binding/Adapters/StringToIntAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace UnityWeld.Binding.Adapters
{
/// <summary>
/// Adapter for converting from a string to an int.
/// </summary>
[Adapter(typeof(string), typeof(int))]
public class StringToIntAdapter : IAdapter
{
public object Convert(object valueIn, AdapterOptions options)
{
return int.Parse((string)valueIn);
}
}
}
2 changes: 2 additions & 0 deletions UnityWeld/UnityWeld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
<Compile Include="Binding\Adapters\DateTimeToStringAdapterOptions.cs" />
<Compile Include="Binding\Adapters\FloatToStringAdapter.cs" />
<Compile Include="Binding\Adapters\FloatToStringAdapterOptions.cs" />
<Compile Include="Binding\Adapters\IntToStringAdapter.cs" />
<Compile Include="Binding\Adapters\StringToFloatAdapter.cs" />
<Compile Include="Binding\Adapters\StringToIntAdapter.cs" />
<Compile Include="Binding\BindingAttribute.cs" />
<Compile Include="Binding\BoundObservableList.cs" />
<Compile Include="Binding\CollectionBinding.cs" />
Expand Down

0 comments on commit 97c4b44

Please sign in to comment.