public static T GetPropertyValue <T>(this SmartObject smartObject, string propertyName) { smartObject.ThrowIfNull("smartObject"); if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException("propertyName"); } var prop = smartObject.Properties.OfType <SmartProperty>() .Where(i => i.Name.StartsWith(propertyName, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); if (prop == null) { throw new Exception(string.Concat("Could not find property ", propertyName, " on smart object ", smartObject.Name)); } string propValueString = prop.Value; if (string.IsNullOrWhiteSpace(propValueString)) { return(default(T)); } object changedType = Convert.ChangeType(propValueString, typeof(T)); return((T)changedType); }
public static void SetNewMethod(this SmartObject smartObject, string methodName, bool ignoreCase = true, bool clearPropertyValues = true) { smartObject.ThrowIfNull("smartObject"); var stringComparison = StringComparison.InvariantCultureIgnoreCase; if (!ignoreCase) { stringComparison = StringComparison.InvariantCulture; } if (clearPropertyValues) { smartObject.ClearPropertyValues(); } foreach (var method in smartObject.AllMethods) { if (method.Name.Equals(methodName, stringComparison)) { smartObject.MethodToExecute = method.Name; } if (clearPropertyValues) { foreach (SmartParameter parameter in method.Parameters) { parameter.Value = null; } } } }
public static SmartMethodBase GetExecutingMethod(this SmartObject smartObject) { smartObject.ThrowIfNull("smartObject"); var method = smartObject.AllMethods.FirstOrDefault(i => i.Name == smartObject.MethodToExecute); return(method); }
public static void AddPropertyOrderBy(this SmartObject smartObject, string propertyName) { smartObject.ThrowIfNull("smartObject"); var listMethod = smartObject.ListMethods[smartObject.MethodToExecute] as SmartListMethod; listMethod.OrderBy.Add(listMethod.ReturnProperties[propertyName], OrderByDirection.ASC); }
public static void VerifyAllReturnPropertiesHasValues(SmartObject smartObject) { smartObject.ThrowIfNull("smartObject"); var method = smartObject.GetMethod(smartObject.MethodToExecute); SmartObjectHelper.VerifyAllReturnPropertiesHasValues(method); }