Passing dynamic content item to a function

Jan 4, 2015 at 5:39 PM
Edited Jan 4, 2015 at 5:39 PM
I want to pass a content item to a function. Something like this:
   @foreach (var Content in AsDynamic(Data["SortByDatePosted"]) )
        SomeFunction( Content );
I have defined SomeFunction like this:
   public void SomeFunctio( ToSic.SexyContent.DynamicEntity Content)
But, if I do that, I get an error when I try to use Content.Field1, etc inside of the function:

error CS1061: 'ToSic.SexyContent.DynamicEntity' does not contain a definition for 'Field1' and no extension method 'Field1' accepting a first argument of type 'ToSic.SexyContent.DynamicEntity' could be found (are you missing a using directive or an assembly reference?)

What's the correct way to do this?

Jan 6, 2015 at 12:27 PM
Edited Jan 6, 2015 at 12:27 PM
In order to dynamically access members of a DynamicEntity object, it must be declared as dynamic. Please try the following signature for SomeFunction:
public void SomeFunction(dynamic Content)