Interface IDynamicStack
This is a dynamic object which contains multiple dynamic objects (Sources). It will try to find a value inside each source in the order the Sources are managed.
Inherited Members
Namespace: ToSic.Sxc.Data
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi]
public interface IDynamicStack : ISxcDynamicObject, ICanDebug
Remarks
New in 12.02
Properties
| Improve this Doc View SourceAnyBooleanProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .IsFemale
or whatever other property your item has.
If it's a true/false, it will just magically work and return a bool
. If it doesn't exist, it will return null.
Declaration
bool AnyBooleanProperty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
AnyChildrenProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Tags
or whatever other property your item has.
If it's contains relationships, it will just magically work and return a list of further DynamicEntity
objects.
If it doesn't exist, it will return null.
Declaration
IEnumerable<DynamicEntity> AnyChildrenProperty { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ToSic.Sxc.Data.DynamicEntity> |
Remarks
Very often you'll want to use LINQ to further sort or query these items.
But the Razor compiler cannot know that it got a list, so using .Any()
or similar fails.
To fix this, put an AsList
around it - a bit like AsList(myThing.Tags)
.
Sometimes you'll also need to help a bit more with AsList(myThings.Tags as object)
.
Now you can do things like var tags = AsList(myThings.Tags as object); if (myTags.Any()) {...}
Read more about this in the Dnn LINQ Tutorials
AnyDateTimeProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Birthday
or whatever other property your item has.
If it's a date/time, it will just magically work and return a DateTime
. If it doesn't exist, it will return null.
Declaration
DateTime AnyDateTimeProperty { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
AnyJsonProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Gps
or whatever other property your item has.
If the field contains JSON, it will just magically work and return a string
.
If it doesn't exist, it will return null.
Declaration
string AnyJsonProperty { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Very often you'll want to use the Json as a dynamic object again.
Just pass the result through AsDynamic
and it will work.
Example: var gps = AsDynamic(myThing.Gps); var lat = gps.Lat;
Read more about this in the Dnn JSON Tutorials
AnyLinkOrFileProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Image
or whatever other property your item has.
If it's a link, it will just magically work and return a string
. If it doesn't exist, it will return null.
Declaration
string AnyLinkOrFileProperty { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Note that many internal references in the CMS use file:2742
or similar. This will automatically be resolved to the real
link which your output needs.
AnyNumberProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .Length
or whatever other property your item has.
If it's a number, it will just magically work and return a double
. If it doesn't exist, it will return null.
Declaration
double AnyNumberProperty { get; }
Property Value
Type | Description |
---|---|
System.Double |
AnyStringProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .FirstName
or whatever other property your item has.
If it's a string, it will just magically work. If it doesn't exist, it will return null.
Declaration
string AnyStringProperty { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Remember to use @Html.Raw(...)
if you want the html to be preserved and not cleaned when placed in the page.
AnyTitleOfAnEntityInTheList
If this DynamicEntity carries a list of items (for example a BlogPost.Tags
which behaves as the first Tag, but also carries all the tags in it)
Then you can also use DynamicCode to directly navigate to a sub-item, like Blogs.Tags.WebDesign
.
Declaration
IEnumerable<DynamicEntity> AnyTitleOfAnEntityInTheList { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ToSic.Sxc.Data.DynamicEntity> |
Remarks
New in 12.03
Methods
| Improve this Doc View SourceBool(String, Boolean)
Get a property and return the value as a bool
.
If conversion fails, will return default false
or what is specified in the fallback
.
Declaration
bool Bool(string name, bool fallback = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Boolean | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Boolean | Value as |
Remarks
Added in 16.01
DateTime(String, DateTime)
Get a property and return the value as a DateTime
.
If conversion fails, will return default 0001-01-01
or what is specified in the fallback
.
Declaration
DateTime DateTime(string name, DateTime fallback = default(DateTime))
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.DateTime | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.DateTime | Value as |
Remarks
Added in 16.01
Decimal(String, Decimal)
Get a property and return the value as a decimal
.
If conversion fails, will return default 0
or what is specified in the fallback
.
Declaration
decimal Decimal(string name, decimal fallback = 0M)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Decimal | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Decimal | Value as |
Remarks
Added in 16.01
Double(String, Double)
Get a property and return the value as a double
.
If conversion fails, will return default 0
or what is specified in the fallback
.
Declaration
double Double(string name, double fallback = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Double | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Double | Value as |
Remarks
Added in 16.01
Float(String, Single)
Get a property and return the value as a float
.
If conversion fails, will return default 0
or what is specified in the fallback
.
Declaration
float Float(string name, float fallback = 0F)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Single | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Single | Value as |
Remarks
Added in 16.01
Get(String)
Get a value of the entity. Usually you will prefer the quick access like @content.FirstName - which will give you the same things as content.Get("FirstName"). There are two cases to use this:
- when you dynamically assemble the field name in your code, like when using App.Resources or similar use cases.
- to access a field which has a conflicting name with this object, like Get("Parents")
Declaration
dynamic Get(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Object | An object which can be either a string, number, boolean or List<IDynamicEntity>, depending on the field type. Will return null if the field was not found. |
Get(String, String, String, Boolean, Nullable<Boolean>)
Get a property using the string name. Only needed in special situations, as most cases can use the object.name directly
Declaration
dynamic Get(string name, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", string language = null, bool convertLinks = true, bool? debug = default(bool? ))
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the property name like |
System.String | noParamOrder | |
System.String | language | Optional language code - like "de-ch" to prioritize that language |
System.Boolean | convertLinks | Optionally turn off if links like file:72 are looked up to a real link. Default is true. |
System.Nullable<System.Boolean> | debug | Set true to see more details in Insights how the value was retrieved. |
Returns
Type | Description |
---|---|
System.Object | a dynamically typed result, can be string, bool, etc. |
Get<TValue>(String)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
Declaration
TValue Get<TValue>(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the property name like |
Returns
Type | Description |
---|---|
TValue | The typed value, or the |
Type Parameters
Name | Description |
---|---|
TValue | The expected type, like |
Remarks
Added in v15
Get<TValue>(String, String, TValue)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
Since the parameter fallback
determines the type TValue
you can just write this like
`Content.Get("Title", fallback: "no title")
Declaration
TValue Get<TValue>(string name, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", TValue fallback = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the property name like |
System.String | noParamOrder | |
TValue | fallback | the fallback value to provide if not found |
Returns
Type | Description |
---|---|
TValue | The typed value, or the |
Type Parameters
Name | Description |
---|---|
TValue | The expected type, like |
Remarks
Added in v15
GetSource(String)
Get a source object which is used in the stack. Returned as a dynamic object.
Declaration
dynamic GetSource(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Object | A dynamic object like a IDynamicEntity or similar. If not found, it will return a source which just-works, but doesn't have data. |
Remarks
Added in 2sxc 12.03
Int(String, Int32)
Get a property and return the value as a int
.
If conversion fails, will return default 0
or what is specified in the fallback
.
Declaration
int Int(string name, int fallback = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Int32 | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Int32 | Value as |
Remarks
Added in 16.01
Long(String, Int64)
Get a property and return the value as a long
.
If conversion fails, will return default 0
or what is specified in the fallback
.
Declaration
long Long(string name, long fallback = 0L)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.Int64 | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.Int64 | Value as |
Remarks
Added in 16.01
String(String, String)
Get a property and return the value as a string
.
If conversion fails, will return default null
or what is specified in the fallback
.
Declaration
string String(string name, string fallback = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | property name |
System.String | fallback | optional fallback if conversion fails |
Returns
Type | Description |
---|---|
System.String | Value as |
Remarks
Added in 16.01
Url(String)
Get a url from a field. This will auto-convert values such as file:72
or page:14
.
Declaration
string Url(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The field name. |
Returns
Type | Description |
---|---|
System.String | A url converted if possible. If the field contains anything else such as |