Class ObjectExtensions
Provides object extension methods.
Inheritance
System.Object
Namespace: Umbraco.Core
Assembly: Umbraco.Core.dll
Syntax
public static class ObjectExtensions
Methods
View SourceAsEnumerableOfOne<T>(T)
Declaration
public static IEnumerable<T> AsEnumerableOfOne<T>(this T input)
Parameters
Type | Name | Description |
---|---|---|
T | input |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> |
Type Parameters
Name | Description |
---|---|
T |
DisposeIfDisposable(Object)
Declaration
public static void DisposeIfDisposable(this object input)
Parameters
Type | Name | Description |
---|---|---|
System.Object | input |
ToDictionary<TVal>(Object, String[])
Turns object into dictionary
Declaration
public static IDictionary<string, TVal> ToDictionary<TVal>(this object o, params string[] ignoreProperties)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o | |
System.String[] | ignoreProperties | Properties to ignore |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, TVal> |
Type Parameters
Name | Description |
---|---|
TVal |
ToDictionary<T, TProperty, TVal>(T, Expression<Func<T, TProperty>>[])
Converts an object into a dictionary
Declaration
public static IDictionary<string, TVal> ToDictionary<T, TProperty, TVal>(this T o, params Expression<Func<T, TProperty>>[] ignoreProperties)
Parameters
Type | Name | Description |
---|---|---|
T | o | |
System.Linq.Expressions.Expression<System.Func<T, TProperty>>[] | ignoreProperties |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, TVal> |
Type Parameters
Name | Description |
---|---|
T | |
TProperty | |
TVal |
ToObjectDictionary<T>(T, Func<PropertyInfo, String>)
Converts an object's properties into a dictionary.
Declaration
public static Dictionary<string, object> ToObjectDictionary<T>(T obj, Func<PropertyInfo, string> namer = null)
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to convert. |
System.Func<System.Reflection.PropertyInfo, System.String> | namer | A property namer function. |
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Object> | A dictionary containing each properties. |
Type Parameters
Name | Description |
---|---|
T |
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 |
---|---|---|
System.Object | input | The input. |
System.Type | target | The type to convert to |
Returns
Type | Description |
---|---|
Attempt<System.Object> | The Attempt<TResult> |
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 |
---|---|---|
System.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