C # Access dynamic property on interface

I am playing with the FluentSecurity library for asp.net mvc. One of the interfaces opened by this library ISecurityContextis as shown below:

public interface ISecurityContext
{
    dynamic Data { get; }
    bool CurrenUserAuthenticated();
    IEnumerable<object> CurrenUserRoles();
}

When I try to access the Data property (as shown below), it is not available. Although two other methods seem to be available.

public class ExperimentalPolicy : ISecurityPolicy
{
    public PolicyResult Enforce(ISecurityContext context)
    {
        dynamic data = context.Data; // Data property is not accessible.
    }
}

What am I missing? Thank.

+5
source share
2 answers

Property Datac is ISecurityContextnot introduced before version 2.0 . The default value set with nuget without preloading is 1.4 . What does not have a property . Make sure you are using the correct version!

+2
source

The following steps performed as expected, is there anything I do other than you?

void Main()
{
  ATest t = new ATest();
  Experiment z = new Experiment();

  z.TestTest(t);
}

public class ATest : ITest
{
  public dynamic Data {get; set;}

  public ATest()
  {
     Data = new { Test = "This is a string" };
  }
}

// Define other methods and classes here
public interface ITest
{
  dynamic Data { get; }
}

public class Experiment
{
    public int TestTest(ITest context)
    {
       dynamic data = context.Data; 

       Console.WriteLine(data.Test);

       return 0;
    }
}
0
source

All Articles