rickstrahl / expando Goto Github PK
View Code? Open in Web Editor NEWExtensible dynamic types for .NET
Extensible dynamic types for .NET
In the case of existing property - access through property or through index should return the same value, but actually an indexer is stored in Properties and not in Object
public class ObjWithProp : Expando
{
public string SomeProp { get; set; }
}
[TestFixture]
[Ignore]
public class ExistingProps
{
[Test]
public void Given_Porp_When_SetWithIndex_Then_PropsValue()
{
//arrange
ObjWithProp obj = new ObjWithProp();
//act
obj.SomeProp = "value1";
obj["SomeProp"] = "value2";
//assert
Assert.AreEqual("value2",obj.SomeProp);
}
}
how to remove property from Westwind.Utilities.Dynamic.Expando
my tries but app crash
any way to remove property from object
public class modelStatic : Westwind.Utilities.Dynamic.Expando
{
public list<string >attachments{get;set;}
....
.. // so other properties
}
dynamic dynamicModel = new ExpandoObject();
dynamicModel = modelStatic;
((IDictionary<String, Object>)dynamicModel)?.Remove("attachments");
Is this available as a NuGet package? Westwind.Utilities
doesn't seem to ship with this project.
I have used the library extensively on a large project where - node'js would be a good fit. I had porformance issues that I suspect trace to it - I would like to improve that - suggestions ?
I mean around 17K rows can take around couple of hours to process
I'm trying to use your project in Unity 3D (added dll to the Unity project). It works for the most part but the TwoWayJsonSerializeExpandoTyped
test results in
{
"Properties": {
"Entered": "2019-02-28T14:38:38.3122796-06:00",
"Company": "West Wind",
"Accesses": 10,
"Address": "32 Kaiea",
"TotalOrderAmounts": 51233.99
},
"email": "[email protected]",
"password": "Seekrit23",
"name": "Rick",
"active": true
}
I tried the same test directly from Expando and get the expected result
{
"Email": "[email protected]",
"Password": "Seekrit23",
"Name": "Rick",
"Active": true,
"ExpiresOn": null,
"Entered": "2019-02-28T14:53:19.3184712-06:00",
"Company": "West Wind",
"Accesses": 10,
"Address": "32 Kaiea",
"TotalOrderAmounts": 51233.99
}
Any ideas why they would have different results?
Inheriting from Expando is great - but if the inheriting class implements strongly typed properties, setting a property dynamically causes some problems. If the types don't agree, casting the dynamic instance back to its static type will give different values for the property depending on whether you use the indexer or property to access it. For example
class Person : Expando
{
public string Name {get; set;}
}
void Main()
{
dynamic ex = new Person();
ex.Name = 100;
var person = ex as Person;
Console.WriteLine(person.Name);
//>> null
Console.WriteLine(person ["Name"]);
//>> 100
}
My apologies if this isn't the correct thread, but it would appear that the Serialization/Deserialization of DateTimeOffset in an Expando object is not handled.
Thank you for such a comprehensive utilities library. I'm glad I've found it.
public class A : Expando
{
public string Prop1 { get; set; }
}
public class B : A
{
public string Prop2 { get; set; }
}
I want to serialize B, but only own properties are serialized, because of this line :
_InstancePropertyInfo = Instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
so I replaced it with this:
_InstancePropertyInfo = Instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) ;
Now, I'm getting weird error during serialization:
"Parameter count mismatch."
Callstack says:
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at Expando.<GetProperties>d__19.MoveNext() in ......
at Expando.<GetDynamicMemberNames>d__9.MoveNext() in .....
at JsonSerializerInternalWriter.SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
As demonstrated by the test case below, the behaviour of [JsonRequired]
from Json.NET is broken.
[TestFixture]
public class JsonRequiredTests
{
[Test]
public void TestJsonRequired()
{
// Passes
Assert.That(() => JsonConvert.DeserializeObject<MyTestCase>("{}"), Throws.InstanceOf<JsonSerializationException>());
// Fails
Assert.That(() => JsonConvert.DeserializeObject<MyTestCase2>("{}"), Throws.InstanceOf<JsonSerializationException>());
}
public class MyTestCase
{
[JsonRequired]
public string SomeProperty { get; set; }
}
public class MyTestCase2 : Westwind.Utilities.Expando
{
[JsonRequired]
public string SomeProperty { get; set; }
}
}
It seems a part of code is used for XML serialization operations, but XML is obsolote for most of us.
If there is performance penalty because of XML feature, could you add only json version of this great work?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.