private async Task Update(Container ctx, T entity, IDictionary <string, string> dict) { foreach (var entry in dict) { var prop = Info.GetProperty <T>(entry.Key); if (prop == null) { continue; } try { var ret = await HandleProperties(ctx, entity, prop, entry.Value); if (ret != null) { prop = Info.GetProperty <T>(ret.Item1); prop.SetValue(entity, ret.Item2); } else { var convertedValue = StringToObject.Parse(prop.PropertyType, entry.Value); prop = Info.GetProperty <T>(entry.Key); prop.SetValue(entity, convertedValue); } } catch (TargetException ex) { _client.Logger.WriteError($"TargetException: {ex.Message}"); } } }
public void TestNullableParameter() { var result = (int?)StringToObject.ConvertValue("10", typeof(int?)); var nullResult = (int?)StringToObject.ConvertValue("", typeof(int?)); Assert.That(result == 10); Assert.That(nullResult == null); }
public void TestStringEmptyParameter() { var result = (int)StringToObject.ConvertValue("", typeof(int)); Assert.That(result == 0); }
public void TestBooleanParameter() { var result = (bool)StringToObject.ConvertValue("true", typeof(bool)); Assert.That(result); }
public void TestEnumParameter() { var result = (TestEnum)StringToObject.ConvertValue("First", typeof(TestEnum)); Assert.That(result == TestEnum.First); }
public void TestCharParameter() { var result = (char)StringToObject.ConvertValue("a", typeof(char)); Assert.That(result == "a".ToCharArray()[0]); }
public void TestDoubleParameter() { var result = (double)StringToObject.ConvertValue("11.11", typeof(double)); Assert.That(result == 11.11d); }
public void TestIntegerParameter() { var result = (int)StringToObject.ConvertValue("11", typeof(int)); Assert.That(result == 11); }
public void TestStringParameter() { var result = (string)StringToObject.ConvertValue("test", typeof(string)); Assert.That(result == "test"); }
public void TestDecimalParameter() { var result = (decimal)StringToObject.ConvertValue("10.00", typeof(decimal)); Assert.That(result == 10.00m); }