FastMember usage
Asked Answered
P

1

7

I have a requirement to extract all public read-write properties that are not enumerable, unless they are a string. This is currently done by refelction and wondering if this can be done with FastMember.

I tried something like the code below but it doesn't do what I want. Can I do this with the current version of FastMember?

Cheers,
Berryl

protected void LoadCache(IHaveEditableStateProperties originator) {
    var type = originator.GetType();
    _accessor = TypeAccessor.Create(type);

    var members = _accessor.GetMembers();
    _editableState = new Dictionary<string, object>();

        foreach (var member in members) {
            if(member.Type == typeof(PropertyInfo)) {
                _editableState.Add(member.Name, _accessor[originator, member.Name]);
            }
        }
    }
    ...
}
Presbyterial answered 11/3, 2013 at 23:26 Comment(0)
E
0

As I understand it, member.Type as returned from FastMember is the return type of the property or method. It should never be PropertyInfo as you are checking for in your code. _accessor[originator, member.Name] should return the current value of the property.

Ekaterinodar answered 26/3, 2014 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.