public virtual string GetLinkNameFromExpression <TResource, TLinkedResource>(Expression <Func <TResource, TLinkedResource> > propertyExpression) { var pi = ExpressionUtils.GetPropertyInfoFromExpression(propertyExpression); var name = CamelCaseUtil.ToCamelCase(pi.Name); return(name); }
public TProperty GetValue <TProperty>(Expression <Func <T, TProperty> > property) { var propertyInfo = property.GetPropertyInfo(); object val; ObjectPropertyValues.TryGetValue(CamelCaseUtil.ToCamelCase(propertyInfo.Name), out val); return((TProperty)val); }
private void RemoveProperty(PropertyInfo propertyInfo) { var name = CamelCaseUtil.ToCamelCase(propertyInfo.Name); BuiltResourceMapping.PropertyGetters.Remove(name); BuiltResourceMapping.PropertySetters.Remove(name); BuiltResourceMapping.PropertySettersExpressions.Remove(name); }
/// <summary> /// Gets the name of the property as it gets serialized in JSON. /// </summary> public string GetPropertyName(PropertyInfo pi) { var name = CamelCaseUtil.ToCamelCase(pi.Name); if (reservedPropertyKeys.Contains(name.ToLower())) { name = string.Format("_{0}", name.ToLower()); } return(name); }
public Dictionary <string, object> GetAttributes(object objectGraph, JsonSerializerSettings settings) { if (settings.NullValueHandling == NullValueHandling.Ignore) { return(PropertyGetters .Where(x => x.Value(objectGraph) != null) .ToDictionary(kvp => CamelCaseUtil.ToCamelCase(kvp.Key), kvp => kvp.Value(objectGraph))); } else { return(PropertyGetters.ToDictionary(kvp => CamelCaseUtil.ToCamelCase(kvp.Key), kvp => kvp.Value(objectGraph))); } }
// TODO ROLA - type handling must be better in here public Dictionary <string, object> GetValuesFromAttributes(Dictionary <string, object> attributes) { var values = new Dictionary <string, object>(); foreach (var propertySetter in PropertySettersExpressions) { object value; attributes.TryGetValue(CamelCaseUtil.ToCamelCase(propertySetter.Key), out value); if (value != null) { values.Add(propertySetter.Key, value); } } return(values); }
public void FilterOut <TProperty>(params Expression <Func <T, TProperty> >[] filter) { ThrowExceptionIfNotScanned(); foreach (var f in filter) { var propertyName = CamelCaseUtil.ToCamelCase(f.GetPropertyInfo().Name); if (_currentTypeSetters.ContainsKey(propertyName)) { _currentTypeSetters.Remove(propertyName); } if (_currentCollectionInfos.ContainsKey(propertyName)) { _currentCollectionInfos.Remove(propertyName); } } }
public static string Transform(string templateParameterName) { string[] words = StringUtils.Split(CamelCaseUtil.ConvertToWords(templateParameterName)); if (words.Length == 1 && words[0].Length <= 3) { return(words[0].ToUpper()); } else { StringBuilder builder = new StringBuilder(); foreach (string word in words) { builder.Append(Ca.Infoway.Messagebuilder.StringUtils.Substring(word, 0, 1).ToUpper()); } return(builder.ToString()); } }
private void AddProperty(PropertyInfo propertyInfo, SerializationDirection direction = SerializationDirection.Both) { var name = CamelCaseUtil.ToCamelCase(propertyInfo.Name); if (BuiltResourceMapping.PropertyGetters.ContainsKey(name) || BuiltResourceMapping.PropertySetters.ContainsKey(name)) { throw new InvalidOperationException(string.Format("Property {0} is already registered on type {1}.", name, typeof(TResource))); } if (direction == SerializationDirection.Out || direction == SerializationDirection.Both) { BuiltResourceMapping.PropertyGetters[name] = propertyInfo.GetValue; } if (direction == SerializationDirection.In || direction == SerializationDirection.Both) { BuiltResourceMapping.PropertySetters[name] = !PropertyScanningConvention.IsLinkedResource(propertyInfo) ? propertyInfo.SetValue : (Action <object, object>)(Delegate)(propertyInfo.ToCompiledSetterAction <object, object>()); } var instance = Expression.Parameter(typeof(object), "i"); var argument = Expression.Parameter(typeof(object), "a"); var setterCall = Expression.Call( Expression.Convert(instance, propertyInfo.DeclaringType), propertyInfo.GetSetMethod(), Expression.Convert(argument, propertyInfo.PropertyType)); Expression <Action <object, object> > expression = Expression.Lambda <Action <object, object> >(setterCall, instance, argument); if (direction == SerializationDirection.In || direction == SerializationDirection.Both) { BuiltResourceMapping.PropertySettersExpressions[name] = expression; } }
public Dictionary <string, object> GetAttributes(object objectGraph) { return(PropertyGetters.ToDictionary(kvp => CamelCaseUtil.ToCamelCase(kvp.Key), kvp => kvp.Value(objectGraph))); }
public void SetValue <TProperty>(Expression <Func <T, TProperty> > property, object value) { var propertyInfo = property.GetPropertyInfo(); ObjectPropertyValues[CamelCaseUtil.ToCamelCase(propertyInfo.Name)] = value; }
protected virtual string Camelize(string name) { return(CamelCaseUtil.ToCamelCase(name)); }