Class ObjectExtensions
Provides object extension methods.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class ObjectExtensions
Methods
View SourceAsEnumerableOfOne<T>(T)
Returns an enumerable containing only the input object.
Declaration
[Obsolete("Please replace uses of this extension method with Enumerable.Repeat(input, 1). This extension method is no longer used in Umbraco and is scheduled for removal in Umbraco 19.")]
public static IEnumerable<T> AsEnumerableOfOne<T>(this T input)
Parameters
| Type | Name | Description |
|---|---|---|
| T | input | The input object. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerable containing only the input object. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the enumerable. |
ToXmlString(object, Type)
Returns an XML serialized safe string representation for the value and type.
Declaration
public static string ToXmlString(this object value, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value. |
| Type | type | The type of the value. This can only be a primitive type or System.Guid and byte[], otherwise an exception is thrown. |
Returns
| Type | Description |
|---|---|
| string | The XML serialized safe string representation. |
ToXmlString<T>(object)
Returns an XML serialized safe string representation for the value and type.
Declaration
public static string ToXmlString<T>(this object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value. |
Returns
| Type | Description |
|---|---|
| string | The XML serialized safe string representation. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
TryConvertTo(object?, Type)
Attempts to convert the input object to the output type.
Declaration
public static Attempt<object?> TryConvertTo(this object? input, Type target)
Parameters
| Type | Name | Description |
|---|---|---|
| object | input | The input. |
| Type | target | The type to convert to. |
Returns
| Type | Description |
|---|---|
| Attempt<object> | The |
Remarks
This code is an optimized version of the original Umbraco method.
TryConvertTo<T>(object?)
Attempts to convert the input object to the output type.
Declaration
public static Attempt<T> TryConvertTo<T>(this object? input)
Parameters
| Type | Name | Description |
|---|---|---|
| object | input | The input. |
Returns
| Type | Description |
|---|---|
| Attempt<T> | The Attempt<TResult>. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to convert to. |
Remarks
This code is an optimized version of the original Umbraco method.