lundi 12 septembre 2016

FastMember and ExpandoObject error

I'm not sure if its supported but I'm trying to get fastmember to give me type information for a dynamic ExpandoObject (using the code below) and I get the error:

System.NotSupportedException: Specified method is not supported. at FastMember.TypeAccessor.GetMembers() at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)

The second test for an anonymous dynamic type works fine, but for some reason it doesn't work with ExpandoObject. Is this supposed to be possible? I can think of an alternative solution by using the ExpandoObject dictionary implementation if not it would be nice to use the same code for everything though.

public class FastMemberTest
{
    [Fact]
    public void GetsMembersOfExpandoObject()
    {
        dynamic dyn = new ExpandoObject();
        dyn.Item1 = 1;
        dyn.Item2 = "Testing";
        var typeAccessor = TypeAccessor.Create(dyn.GetType());

        var members = typeAccessor.GetMembers();

        members.Should().NotBeNull();
    }

    [Fact]
    public void GetsMembersOfDynamicType()
    {
        dynamic dyn = new
        {
            Item1 = 1,
            Item2 = "Testing"
        };
        var typeAccessor = TypeAccessor.Create(dyn.GetType());

        var members = typeAccessor.GetMembers();

    }
}

[Test is Xunit2]





Aucun commentaire:

Enregistrer un commentaire