private KeyValuePair <string, object> FormatProperty(PropertyArgs propertyArgs) { var source = propertyArgs.Source; var propertyName = propertyArgs.Name; var name = _profile.CamelCaseName ? CamelCaseName(propertyName) : propertyName; // Return property formatting if available if (source is Item && _profile.PropertyFormatters.ContainsKey(name.ToLower())) { var prop = InvokeFormatter(_profile.PropertyFormatters[name.ToLower()], propertyArgs); if (prop != null) { return(new KeyValuePair <string, object>(name, prop)); } } // Otherwise proceed with property value formatting var valueFormatters = GetValueFormatters(source); var propValue = propertyArgs.Info != null ? (propertyArgs.GetValue() ?? string.Empty) : string.Empty; var result = FormatValue(propertyArgs, valueFormatters).Result ?? propValue; return(new KeyValuePair <string, object>(name, result)); }
private static async Task <object> InvokeFormattersAsync(PropertyArgs propertyArgs, IEnumerable <FormatterArgs> formatters) { var tasks = formatters.Select(n => Task.FromResult(InvokeFormatter(n, propertyArgs))).ToList(); var results = await Task.WhenAll(tasks); // Although all available formatters are being invoked only one (or none) will be valid for the given property. return(results.SingleOrDefault(n => n != null)); }
private static object InvokeFormatter(FormatterArgs formatterArgs, PropertyArgs propertyArgs) { var source = Activator.CreateInstance(formatterArgs.Type); formatterArgs.Method.Invoke(source, new object[] { propertyArgs }); var formatterSource = source as Formatter; return(formatterSource.IsFormatted ? formatterSource.FormattedObject : null); }
public void Format(PropertyArgs propertyArgs) { var id = propertyArgs.GetValue() as ID; if (id.IsNull) { return; } Set(id.Guid.ToString("D")); }
public void Format(PropertyArgs propertyArgs) { var regEx = new System.Text.RegularExpressions.Regex("[0-9][0-9][0-9][0-9][0-1][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]"); var value = propertyArgs.GetValue().ToString(); if (!regEx.IsMatch(value)) { return; } Set(new DateField(propertyArgs.Source as Field).DateTime); }
private static async Task <object> FormatValue(PropertyArgs propertyArgs, IEnumerable <FormatterArgs> formatterArgs) { // Check if property corresponds to the Field value and invoke field value formatters if available. if (propertyArgs.Source is Field && propertyArgs.Name.Equals("value", StringComparison.OrdinalIgnoreCase)) { var fvQuery = formatterArgs.Where(n => typeof(IFieldValueFormatter).IsAssignableFrom(n.Type)); return(await InvokeFormattersAsync(propertyArgs, fvQuery)); } // Otherwise invoke all non field value formatters. var query = formatterArgs.Where(n => !(typeof(IFieldValueFormatter).IsAssignableFrom(n.Type))); return(await InvokeFormattersAsync(propertyArgs, query)); }
public void Format(PropertyArgs propertyArgs) { var item = propertyArgs.Source as Item; Func <string, bool> nameIsHidden = s => ItemProfile.HiddenFieldNames.Any(n => s.IndexOf(n, StringComparison.OrdinalIgnoreCase) != -1); var query = from obj in item.Fields where !nameIsHidden(obj.Name) select obj; var tasks = query.Select(obj => Task.FromResult(new FormatHelper(ItemProfile).FormatObjectAsync(obj))).ToArray(); Task.WaitAll(tasks); var result = tasks.Select(n => n.Result.Result); //.Where(n => n.HasValues); Set(result); }
public void Format(PropertyArgs propertyArgs) { var linkField = new LinkField(propertyArgs.Source as Field); if (string.IsNullOrEmpty(linkField.Url) && linkField.TargetID.IsNull) { return; } var linkUrl = linkField.TargetItem != null?LinkManager.GetItemUrl(linkField.TargetItem) : linkField.Url; var value = new { text = linkField.Text, url = linkUrl, anchor = linkField.Anchor, target = linkField.Target }; Set(value); }
public void Format(PropertyArgs propertyArgs) { Set(new { value = "Foo" }); }