예제 #1
0
 public static PropertyInfo[] ArraySort(PropertyInfo[] properties)
 {
     properties = properties.Select(x => new { Property = x })
         .OrderBy(x => x.Property.Name != null ? x.Property.Name : Constants.NotApplicable)
         .Select(x => x.Property)
         .ToArray();
     return properties;
 }
예제 #2
0
		public static PropertySet[] RequireAll(ComponentModel model, PropertyInfo[] properties,
		                                       PropertySetBuilder propertySetBuilder)
		{
			return properties.Select(p => propertySetBuilder(p, false)).ToArray();
		}
예제 #3
0
        public IResourceTypeRegistration BuildRegistration(Type type, string resourceTypeName = null,
            Func<ParameterExpression, string, BinaryExpression> filterByIdFactory = null,
            Func<ParameterExpression, Expression> sortByIdFactory = null,
            PropertyInfo[] includeRelationships = null)
        {
            if (resourceTypeName == null)
                resourceTypeName = _namingConventions.GetResourceTypeNameForType(type);

            var fieldMap = new Dictionary<string, ResourceTypeField>();

            var idProperty = CalculateIdProperty(type);
            if (idProperty == null)
                throw new InvalidOperationException(String.Format(
                    "Unable to determine Id property for type `{0}`.", type.Name));

            var props = type.GetProperties().OrderBy(p => p.Name);
            foreach (var prop in props)
            {
                if (prop == idProperty) continue;

                var ignore = prop.CustomAttributes.Any(c => c.AttributeType == typeof (JsonIgnoreAttribute));
                if (ignore) continue;

                var property = CreateResourceTypeField(prop);
                var jsonKey = property.JsonKey;

                if (jsonKey == "id")
                    throw new InvalidOperationException(
                        String.Format(
                            "Failed to register type `{0}` because it contains a non-id property that would serialize as \"id\".",
                            type.Name));

                if (jsonKey == "type")
                    throw new InvalidOperationException(
                        String.Format(
                            "Failed to register type `{0}` because it contains a property that would serialize as \"type\".",
                            type.Name));

                if (fieldMap.ContainsKey(jsonKey))
                    throw new InvalidOperationException(
                        String.Format(
                            "Failed to register type `{0}` because contains multiple properties that would serialize as `{1}`.",
                            type.Name, jsonKey));

                fieldMap[jsonKey] = property;
            }

            if (filterByIdFactory == null)
            {
                filterByIdFactory = (param, id) =>
                {
                    var propertyExpr = Expression.Property(param, idProperty);
                    var idExpr = Expression.Constant(id);
                    return Expression.Equal(propertyExpr, idExpr);
                };
            }

            if (sortByIdFactory == null)
            {
                sortByIdFactory = param => Expression.Property(param, idProperty);
            }

            var allincludeRelationships = new List<string>();

            if (includeRelationships != null)
            {
                allincludeRelationships.AddRange(includeRelationships.Select(CreateResourceTypeField).Select(property => property.JsonKey));
            }

            return new ResourceTypeRegistration(type, idProperty, resourceTypeName, fieldMap, filterByIdFactory,
                sortByIdFactory, allincludeRelationships.ToArray());
        }
예제 #4
0
		public static PropertySet[] Default(ComponentModel model, PropertyInfo[] properties,
		                                    PropertySetBuilder propertySetBuilder)
		{
			return properties.Select(p => propertySetBuilder(p, true)).ToArray();
		}
예제 #5
0
 private string Line(PropertyInfo[] properties, Object item)
 {
     return String.Join("\t", properties.Select(prop => prop.GetValue(item, null)));
 }
예제 #6
0
 private string Header(PropertyInfo[] properties)
 {
     return String.Join("\t", properties.Select(prop => prop.Name));
 }
 private IEnumerable<Expression> GetPropertyExpressions(PropertyInfo[] properties)
 {
     return properties.Select(this.GetPropertyExpression);
 }
예제 #8
0
    /// <summary>
    /// If command has a ListParameter, assign unmatched  values from <c>numbered</c> to it.
    /// </summary>
    /// <param name="cmd">The command</param>
    /// <param name="properties">The command properties</param>
    /// <param name="numbered">Unmatched parameteres from ExtractParameters call</param>
    private void AssignListParameter(ICommand cmd, PropertyInfo[] properties, string[] numbered)
    {
      var listProperty = properties.FirstOrDefault(p => CommandInspector.GetListParameter(p) != null);
      if (listProperty == null)
        return;

      var numberedParameters = properties.Select(CommandInspector.GetNumberedParameter)
                         .Where(p => p != null)
                         .Select(p => p.Number);

      int numberedParametersToSkip = (numberedParameters.Any()) ? numberedParameters.Max() + 1 : 0;
      var list = numbered.Skip(numberedParametersToSkip).ToList();
      list = (from element in list
        select Parser.PerformSubstitution(_context, element)).ToList();
#if NET45
      listProperty.SetValue(cmd, list);
#else
      listProperty.SetValue(cmd, list, null);
#endif
    }
 public static string GetChainName(PropertyInfo[] chain)
 {
     return String.Join (".", chain.Select (p => p.Name));
 }