public void Map_maps_DynamicObject() { var vm = new MyDynamicObject(); var res = _CSharpToJavascriptConverter.Map(vm); res.ToString().Should().Be("{\"nickelback\":\"nickelback\",\"toto\":\"toto\"}"); }
public void Map_Maps_DynamicObject() { var vm = new MyDynamicObject(); var res = _CSharpToGlueMapper.Map(vm); res.ToString().Should().Be("{\"nickelback\":\"nickelback\",\"toto\":\"toto\"}"); }
static void Main(string[] args) { dynamic obj = new MyDynamicObject(); obj.MyEvent += new EventHandler(handler); obj.MyEvent(null, EventArgs.Empty); obj.MyEvent -= new EventHandler(handler); }
protected dynamic BuildJsonResultObject(OperationResultType resultType, string msg, params KeyValuePair <string, object>[] extraProperties) { dynamic obj = new MyDynamicObject(); obj.set("code", resultType); obj.set("message", msg); foreach (var item in extraProperties) { obj.set(item.Key, item.Value); } return(obj); }
public void DynamicObjectTestOnePropertyMultipleTimes() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; for (int i = 0; i < 10000; i++) { var serialized = JsonSerializer.Generic.Utf16.Serialize(dynamicObject); Assert.NotNull(serialized); var deserialized = JsonSerializer.Generic.Utf16.Deserialize <dynamic>(serialized); Assert.NotNull(deserialized); Assert.Equal("Hello World", (string)deserialized.Text); } }
public void DynamicObjectTestOnePropertyUtf8() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; var serialized = JsonSerializer.Generic.Utf8.Serialize(dynamicObject); Assert.NotNull(serialized); var deserialized = JsonSerializer.Generic.Utf8.Deserialize <dynamic>(serialized); Assert.NotNull(deserialized); Assert.Equal("Hello World", (string)deserialized.Text); }
public void DynamicObjectTestOnePropertyMultipleTimesJil() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; var serialized = JSON.SerializeDynamic(dynamicObject); Assert.NotNull(serialized); for (int i = 0; i < 10000; i++) { var deserialized = JSON.DeserializeDynamic(serialized); Assert.NotNull(deserialized); Assert.Equal("Hello World", (string)deserialized.Text); } }
public void DynamicObjectSerializeTwiceDifferentEncodingSecond() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; dynamicObject.Value = 5; dynamicObject.Array = new string[] { "Hello", "World" }; var serialized = JsonSerializer.Generic.Utf16.Serialize(dynamicObject); Assert.NotNull(serialized); var deserialized = JsonSerializer.Generic.Utf16.Deserialize <dynamic>(serialized); var serialized2 = JsonSerializer.Generic.Utf8.Serialize(deserialized); Assert.Equal(serialized, Encoding.UTF8.GetString(serialized2)); }
public void ExpandoUtf16() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; dynamicObject.Value = 5; dynamicObject.Array = new string[] { "Hello", "World" }; var serialized = JsonSerializer.Generic.Utf16.Serialize(dynamicObject); Assert.NotNull(serialized); var deserialized = JsonSerializer.Generic.Utf16.Deserialize <dynamic>(serialized); var serialized2 = JsonSerializer.Generic.Utf16.Serialize(deserialized); Assert.Equal(serialized, serialized2); }
public void DynamicObjectTestTwoProperties() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; dynamicObject.Value = 5; var serialized = JsonSerializer.Generic.Utf16.Serialize(dynamicObject); Assert.NotNull(serialized); var deserialized = JsonSerializer.Generic.Utf16.Deserialize <dynamic>(serialized); Assert.NotNull(deserialized); Assert.Equal("Hello World", (string)deserialized.Text); Assert.Equal(5, (int)deserialized.Value); }
public void When_ReadValue() { var target = new MyControl(); dynamic source = new MyDynamicObject(); target.SetBinding( MyControl.MyPropertyProperty, new Windows.UI.Xaml.Data.Binding() { Path = new PropertyPath("TestDynamicProperty") } ); source.TestDynamicProperty = "Dynamic Value"; target.DataContext = source; Assert.AreEqual("Dynamic Value", target.MyProperty); }
public void DynamicObjectTestTwoPropertiesIncludeNull() { dynamic dynamicObject = new MyDynamicObject(); dynamicObject.Text = "Hello World"; dynamicObject.Value = 5; dynamicObject.NullValue = null; var serialized = JsonSerializer.Generic.Utf16.Serialize <MyDynamicObject, IncludeNullsOriginalCaseResolver <char> >(dynamicObject); Assert.NotNull(serialized); Assert.Contains("null", serialized); var deserialized = JsonSerializer.Generic.Utf16.Deserialize <MyDynamicObject, IncludeNullsOriginalCaseResolver <char> >(serialized); Assert.NotNull(deserialized); Assert.Equal("Hello World", (string)deserialized.Text); Assert.Equal(5, (int)deserialized.Value); Assert.Null(deserialized.NullValue); }
public void CreateFromDynamic() { string expectedJson = "{\"int\":12,\"str\":\"hello\",\"jv\":[1,{\"a\":true}],\"dyn\":{\"char\":\"c\",\"null\":null}}"; MyDynamicObject obj = new MyDynamicObject(); obj.fields.Add("int", 12); obj.fields.Add("str", "hello"); obj.fields.Add("jv", new JsonArray(1, new JsonObject { { "a", true } })); MyDynamicObject dyn = new MyDynamicObject(); obj.fields.Add("dyn", dyn); dyn.fields.Add("char", 'c'); dyn.fields.Add("null", null); JsonValue jv = JsonValueExtensions.CreateFrom(obj); Assert.Equal(expectedJson, jv.ToString()); }
public void Execute() { // // DynamicObjectクラスのサブクラスを作成する // ことで、簡単にdynamic対応のクラスを作成することが // できる。実際、DynamicObjectの中には多くのメソッドが // 定義されているが、動的な値を格納するようにするだけであれば // TryGetMember // TrySetMember // メソッドをオーバーライドすれば事足りる。 // dynamic obj = new MyDynamicObject(); obj.age = 100; obj.name = "name1"; Output.WriteLine(obj.GetType().Name); Output.WriteLine(obj.AGE); Output.WriteLine(obj.NAME); }
public void Execute() { // // DynamicObjectクラスのサブクラスを作成する // ことで、簡単にdynamic対応のクラスを作成することが // できる。実際、DynamicObjectの中には多くのメソッドが // 定義されているが、動的な値を格納するようにするだけであれば // TryGetMember // TrySetMember // メソッドをオーバーライドすれば事足りる。 // dynamic obj = new MyDynamicObject(); obj.age = 100; obj.name = "name1"; Output.WriteLine(obj.GetType().Name); Output.WriteLine(obj.AGE); Output.WriteLine(obj.NAME); }
public void When_Unknown_Property() { var target = new MyControl(); dynamic source = new MyDynamicObject(); target.SetBinding( MyControl.MyPropertyProperty, new Windows.UI.Xaml.Data.Binding() { Path = new PropertyPath("UnknownProperty") , Mode = BindingMode.TwoWay } ); target.DataContext = source; Assert.IsNull(target.MyProperty); target.MyProperty = "42"; Assert.AreEqual("42", source.UnknownProperty); }