Pass Entity

Feb 7, 2014 at 1:21 AM
I have 2 content types that are related through an entity field.

In Razor I access the object using
var otherContent = Content.RelatedInfo[0]
This works well and I can access the values in the other content.
I have a
@helper doStuff(???){} 
I want to pass the otherContent object to the doStuff() helper. What type should be declared for the parameter?
Feb 7, 2014 at 9:53 AM
Just do a
to find the returned type
Feb 7, 2014 at 4:36 PM
I appreciate this suggestion but it doesn't quite work with 2Sexy Content Types, or I don't know how to properly use the type returned.

@otherContent.GetType() always returns "ToSic.SexyContent.DynamicEntity".

When using this type in the parameter of the helper such as:
@helper doStuff(ToSic.SexyContent.DynamicEntity passedObject)
it causes an error because myField is not recognized.
This is totally reasonable as it is not the type I want it to be, it is a "ToSic.SexyContent.DynamicEntity" type.
I could also get the data there through a general Object but I am unsure of how to cast this back so I can access fields.

In case it isn't clear what I mean by this, the similar equivalent that I know works with a string instead of the 2Sexy Content Type is:
    Object s;
    string z = "blah";
    s = z;
    string b = (string)s;
I feel like I am missing something like:
@helper doStuff(ToSic.SexyContent.DynamicEntity passedObject)
    var myObject = (MyContentType) passedObject;
How can I make the fields inside the DynamicEntity accessible from a helper?
Feb 10, 2014 at 7:15 AM
Edited Feb 10, 2014 at 7:16 AM
A Content object is technically of type ToSic.SexyContent.DynamicEntity. But it is declared as dynamic, which means that the properties you are accessing of it will be resolved at runtime. There is no type like MyContentType for each Content type.

Use the dynamic keyword:
@helper doStuff(dynamic passedObject)
Hope you get it working.

Marked as answer by RacerNerd on 2/10/2014 at 8:57 AM
Feb 10, 2014 at 4:59 PM
Thanks for the suggestion. This worked well.