private static void TrySetProperty <T>(PropertyInfo property, object destinationModel, IFieldSet source, ITridionViewModelPropertyAttribute tridionAttribute, IPage page = null) { T value; if (source != null && TryResolveViewModelProperty(source, tridionAttribute, out value, page)) { property.SetValue(destinationModel, value, null); } }
private static bool TryResolveViewModelProperty <T>(IComponent source, ITridionViewModelPropertyAttribute attribute, out T value, IPage page = null) { value = default(T); var objAttribute = attribute as ITridionViewModelPropertyAttribute <T>; if (objAttribute != null) { value = objAttribute.GetValue(source, page); } return(objAttribute != null); }
private static void TrySetMultiValueProperty <T>(PropertyInfo property, object destinationModel, IFieldSet source, ITridionViewModelPropertyAttribute tridionAttribute, IPage page = null) { IEnumerable <T> value; if (source != null && TryResolveMultiValueViewModelProperty(source, tridionAttribute, out value, page)) { if (tridionAttribute is BaseNestedTridionViewModelPropertyAttribute) { var nestedAttr = (BaseNestedTridionViewModelPropertyAttribute)tridionAttribute; var caster = typeof(System.Linq.Enumerable) .GetMethod("Cast", new[] { typeof(IEnumerable) }) .MakeGenericMethod(nestedAttr.TargetType); var castedValue = caster.Invoke(null, new object[] { value }); property.SetValue(destinationModel, castedValue, null); } else { property.SetValue(destinationModel, value, null); } } }
private static void TrySetAllValues(IFieldSet fields, object destinationModel, ITridionViewModelPropertyAttribute tridionAttribute, PropertyInfo property, IPage page = null) { if (tridionAttribute.IsMultiValue) { TrySetMultiValueProperty <double>(property, destinationModel, fields, tridionAttribute, page); TrySetMultiValueProperty <bool>(property, destinationModel, fields, tridionAttribute, page); TrySetMultiValueProperty <DateTime>(property, destinationModel, fields, tridionAttribute, page); TrySetMultiValueProperty <string>(property, destinationModel, fields, tridionAttribute, page); TrySetMultiValueProperty <object>(property, destinationModel, fields, tridionAttribute, page); } else { TrySetProperty <double>(property, destinationModel, fields, tridionAttribute, page); TrySetProperty <bool>(property, destinationModel, fields, tridionAttribute, page); TrySetProperty <DateTime>(property, destinationModel, fields, tridionAttribute, page); TrySetProperty <string>(property, destinationModel, fields, tridionAttribute, page); TrySetProperty <object>(property, destinationModel, fields, tridionAttribute, page); } }
private static bool TryResolveMultiValueViewModelProperty <T>(IFieldSet source, ITridionViewModelPropertyAttribute attribute, out IEnumerable <T> values, IPage page = null) { values = null; var objAttribute = attribute as ITridionViewModelPropertyAttribute <T>; if (objAttribute != null) { values = objAttribute.GetMultiValue(source, page); } return(objAttribute != null); }