Skip to main content

Get

Gets a field from an entry by fieldName and returns a dynamic object instance.

Syntax

C#
public dynamic Get(string fieldName, bool autoResolve = true)
{
}

Parameters

fieldName

Type: string
The name of the requested field

autoResolve

Type: string
If set to true for a singular/list of entries, assets or images, it will automatically request the linked resource when invoked. A value of false should be specified if you only require the link properties such as Uri or contentTypeId and do not want the performance overhead of retrieving the entire resource. The default is true.

Remarks

Returns null if the field is not found or if the field value is null.

Example

C#
// Get the title field as dynamic
dynamic title = entry.Get("title")

Get <T>

Gets a field from an entry by fieldName and returns a typed object instance.

Syntax

C#
public T Get<T>(string fieldName, bool autoResolve = true)
{
}

Parameters

T

The type to attempt to cast the field data to. The type will either be a DataType, a supported DataFormat type or a custom type.

fieldName

Type: string
The name of the requested field

autoResolve

Type: string
If set to true for a singular/list of entries, assets or images, it will automatically request the linked resource when invoked. A value of false should be specified if you only require the link properties such as Uri or contentTypeId and do not want the performance overhead of retrieving the entire resource. The default is true.git

Remarks

If the API cannot successfully cast or convert the field value then it will return the default for the specified type. Requesting field values by the wrong type will not result in exceptions being thrown.

Example

C#
// Get the title field as defined type
string title = entry.Get<string>("title")

HasValue

Determines whether the field exists and the value is not null.

Syntax

C#
public bool HasValue(string fieldName)
{
}

Parameters

fieldName

Type: string
The name of the field to check

Return value

Type: boolean
true if the field exists and is not null, otherwise false

Remarks

If the fieldName is not defined in the content type that the entry is based on then it will return null.

Example

C#
if (entry.HasValue("title"))
{
    // Get the location field as type
    Location title = entry.Get<Location>("filmingLocation")
}

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request