예제 #1
0
        public virtual string GetLinkNameFromExpression <TResource, TLinkedResource>(Expression <Func <TResource, TLinkedResource> > propertyExpression)
        {
            var pi   = ExpressionUtils.GetPropertyInfoFromExpression(propertyExpression);
            var name = CamelCaseUtil.ToCamelCase(pi.Name);

            return(name);
        }
예제 #2
0
        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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
 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)));
     }
 }
예제 #6
0
        // 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);
        }
예제 #7
0
 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);
         }
     }
 }
예제 #8
0
 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;
            }
        }
예제 #10
0
 public Dictionary <string, object> GetAttributes(object objectGraph)
 {
     return(PropertyGetters.ToDictionary(kvp => CamelCaseUtil.ToCamelCase(kvp.Key), kvp => kvp.Value(objectGraph)));
 }
예제 #11
0
        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));
 }