Skip to content
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

Deserialize Dynamic Object Support #529

Closed
xpandax76 opened this issue Sep 10, 2020 · 1 comment
Closed

Deserialize Dynamic Object Support #529

xpandax76 opened this issue Sep 10, 2020 · 1 comment

Comments

@xpandax76
Copy link

For my current code, I need to deserialize a yaml file with a few expected properties. There are a few properties I expect in the yaml file such as Name, Type, but the rest of the properties are unknown. My object would have those known properties defined and I want to be able to store the rest of unknow properties in a dictionary<string, object>. below is an example of my class:

public class DynamicObj
{
    [Required]
    public string Name { get; set; }
    public string Type { get; set; }
    private readonly Dictionary<string, object> _dictionary = new Dictionary<string, object>();
    public object this[string key] { get => _dictionary[key]; set => _dictionary[key] = value; }

}

I was trying out creating a custom INodeDeserializer. However, I need the TypeInspector to return the IPropertyDescriptor of the expected properties ( var property = typeDescriptor.GetProperty(expectedType, null, propertyName.Value, ignoreUnmatched);
) and I got stuck here. Do you have any suggestion on the issue?

@earloc
Copy link

earloc commented Oct 21, 2020

Hey @trucnguyen76.
I´m facing the exact same situation atm. You closed the issue here, did you find a way for supporting this scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants