From 97c4b4404e24738bc98475213741f5915f1d1a48 Mon Sep 17 00:00:00 2001 From: Rory Dungan Date: Tue, 4 Jul 2017 11:29:05 +1000 Subject: [PATCH] Added adapters for converting between ints and strings --- UnityWeld/Binding/Adapters/IntToStringAdapter.cs | 14 ++++++++++++++ UnityWeld/Binding/Adapters/StringToIntAdapter.cs | 14 ++++++++++++++ UnityWeld/UnityWeld.csproj | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 UnityWeld/Binding/Adapters/IntToStringAdapter.cs create mode 100644 UnityWeld/Binding/Adapters/StringToIntAdapter.cs diff --git a/UnityWeld/Binding/Adapters/IntToStringAdapter.cs b/UnityWeld/Binding/Adapters/IntToStringAdapter.cs new file mode 100644 index 0000000..3fa6785 --- /dev/null +++ b/UnityWeld/Binding/Adapters/IntToStringAdapter.cs @@ -0,0 +1,14 @@ +namespace UnityWeld.Binding.Adapters +{ + /// + /// Adapter for converting from an int to a string. + /// + [Adapter(typeof(int), typeof(string))] + public class IntToStringAdapter : IAdapter + { + public object Convert(object valueIn, AdapterOptions options) + { + return ((int)valueIn).ToString(); + } + } +} diff --git a/UnityWeld/Binding/Adapters/StringToIntAdapter.cs b/UnityWeld/Binding/Adapters/StringToIntAdapter.cs new file mode 100644 index 0000000..5ca63e0 --- /dev/null +++ b/UnityWeld/Binding/Adapters/StringToIntAdapter.cs @@ -0,0 +1,14 @@ +namespace UnityWeld.Binding.Adapters +{ + /// + /// Adapter for converting from a string to an int. + /// + [Adapter(typeof(string), typeof(int))] + public class StringToIntAdapter : IAdapter + { + public object Convert(object valueIn, AdapterOptions options) + { + return int.Parse((string)valueIn); + } + } +} diff --git a/UnityWeld/UnityWeld.csproj b/UnityWeld/UnityWeld.csproj index 80748d7..9c2b3b7 100644 --- a/UnityWeld/UnityWeld.csproj +++ b/UnityWeld/UnityWeld.csproj @@ -60,7 +60,9 @@ + +