-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request - Client: Ignore JsonIgnore and readonly properties #184
Comments
Fixes #165 |
JsonIgnore has to do with serialization. Can you explain more about your scenario where you need this? If you like, you can create a PR that has just a failing test. |
I'm not sure I can come up with a failing test for it now, but the logic behind this is very simple: |
Imaging this class would look like this in the client:
Now, the readonly property ( |
Have you tried ExcludedProperties on CTC? |
Never heard of it... Lemme check. |
Yes, so I would suggest an extension method that accepts a lambda (strategy pattern). It can be a Func<T, bool>. Then the caller can apply whatever strategy they want. If the delegate returns true, then the method can add the property to The caller can then apply whatever logic they want (read-only, JsonIgnore, no DataMember attribute, etc. |
Makes sense. |
Let's start with the generic method and go from there, perhaps adding overloads for common patterns - maybe accepting a bit mask [Flags] enum. |
We need a way that covers more than one property. |
So the way private void ExcludeProperties(TEntity entity, Func<string, bool> predicate, bool recursive)
{
foreach (var prop in typeof(TEntity).GetRuntimeProperties())
{
if (predicate(prop.Name))
{
ExcludedProperties.Add(prop.Name);
}
}
} Here is the public method that calls the private method. public void ExcludeProperties(Func<string, bool> predicate, bool recursive)
{
foreach (var item in Items)
{
ExcludeProperties(item, predicate, recursive);
}
} How does this look? Cheers, |
The problem with setting up the excluded properties in the CTC is that it must be performed on each CTC individually throughout the entire graph, which doesn't really make sense. |
The recursive flag is there to allow you to do this. We just need to add the CTC type as an argument on the Func, so that the callback knows the CTC type. The approach here is to build out the low level API based on a Strategy pattern, then build a higher level of abstraction on top of that, so you can do things like look for Json attributes. |
Don't worry, we'll get to where you want to be, with a method that does what you want. It's just that I'd like to try for a more extensible design. That way, other criteria can be applied if desired. If you like, I can flesh out the low level API first, and then you can layer your method on top of that. |
I'll try to implement during the week. |
The config can't sit in the CTC. It has to be configured in a global map, via attributes or other per-class/property excludes. |
Hi,
Let's have the CTC (client) ignore any:
JsonIgnore
So the above conditions don't affect the client's entities'
TrackingState
andModifiedProperties
properties.It's likely that addressing this issue will eliminate the source of the issue addressed by #170, I do still think both server-side (#165) and client-side are important, because there could be both scenarios (i.e.
NotMapped
^JsonIgnore
).Can I PR?
The text was updated successfully, but these errors were encountered: