private IDictionary <string, BucketItem> CreateItems(Type target) { PropertyInfo[] infos = target.GetProperties(); IDictionary <string, BucketItem> list = new Dictionary <string, BucketItem>(); foreach (PropertyInfo info in infos) { if (info.CanRead && info.CanWrite) { string fieldName = string.Empty; object[] arg = info.GetCustomAttributes(typeof(IgnoreAttribute), false); if (arg.Length == 0) { const bool visible = true; arg = info.GetCustomAttributes(typeof(NameAttribute), false); if (arg.Length > 0) { var fieldNameAttr = arg[0] as NameAttribute; if (fieldNameAttr != null) { fieldName = fieldNameAttr.Name; } } else { fieldName = info.Name; } arg = info.GetCustomAttributes(typeof(UniqueIdentifierAttribute), true); bool isUnique = arg.Length > 0; // only if not already added. if (!list.ContainsKey(info.Name)) { var newItem = new BucketItem(target, fieldName, info.Name, info.PropertyType, null, isUnique, BinaryOperator.Equal, visible) { Container = this }; list.Add(info.Name, newItem); } } } } return(list); }
private BucketItem ProcessNestedBucket(Bucket bucket) { foreach (string key in bucket.Items.Keys) { BucketItem childItem = bucket.Items[key]; if (childItem.Value != null && !childItem.IsVisited) { childItem.IsVisited = true; return(childItem); } if (childItem.Child != null) { return(ProcessNestedBucket(childItem.Child)); } } return(null); }
private void FillBucketFromMethodCall(BinaryExpression expression, MethodCallExpression methodCallExpression) { var bucketImpl = Buckets.Current; bucketImpl.IsDirty = true; bucketImpl.ClauseItemCount = bucketImpl.ClauseItemCount + 1; Buckets.Current.SyntaxStack.Pop(); if (expression != null) { object value = Expression.Lambda(expression.Right).Compile().DynamicInvoke(); var leafItem = new BucketItem { Name = methodCallExpression.Method.Name, Method = new BucketItem.ExtenderMethod { Name = methodCallExpression.Method.Name, Arguments = methodCallExpression.Arguments, Method = methodCallExpression.Method } }; leafItem.Values.Add(new BucketItem.QueryCondition(value, bucketImpl.Relation)); bucketImpl.CurrentTreeNode.Nodes.Add(new TreeNode.Node() { Value = leafItem }); } else { var value = Expression.Lambda(methodCallExpression.Object).Compile().DynamicInvoke() as IEnumerable <object>; if (value != null) { var memberExpression = methodCallExpression.Arguments[0] as MemberExpression; if (memberExpression != null) { string memberName = memberExpression.Member.Name; if (bucketImpl.Items.ContainsKey(memberName)) { var leafItem = new BucketItem { DeclaringType = memberExpression.Member.DeclaringType, Name = bucketImpl.Items[memberName].Name, ProperyName = bucketImpl.Items[memberName].ProperyName, PropertyType = bucketImpl.Items[memberName].PropertyType, Unique = bucketImpl.Items[memberName].Unique, Child = bucketImpl.Items[memberName].Child, Container = bucketImpl.Items[memberName].Container }; foreach (object item in value) { leafItem.Values.Add(new BucketItem.QueryCondition(item, BinaryOperator.Contains)); } bucketImpl.CurrentTreeNode.Nodes.Add(new TreeNode.Node { Value = leafItem }); } } } } }
private void FillBucket(BucketImpl bucket, PropertyInfo info, object value, MemberExpression memberExpression) { bucket.ClauseItemCount = bucket.ClauseItemCount + 1; var expression = memberExpression.Expression; Buckets.Current.SyntaxStack.Pop(); string[] parts = expression.ToString().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); Bucket current = bucket; bool nested = false; for (int index = 1; index < parts.Length; index++) { Type propertyType = current.Items[parts[index]].PropertyType; if (!propertyType.IsPrimitive && propertyType.FullName.IndexOf("System") == -1 && !propertyType.IsEnum) { if (current.Items[parts[index]].Child == null) { current.Items[parts[index]].Child = BucketImpl.NewInstance(propertyType).Init(); current.Items[parts[index]].Child.Container = current.Items[parts[index]]; } // move on. current = current.Items[parts[index]].Child; nested = true; } } BucketItem item = null; if (current != null && nested) { foreach (PropertyInfo property in info.PropertyType.GetProperties()) { object targetValue = property.GetValue(value, null); if (targetValue != null && !targetValue.EqualsDefault(property.Name, value)) { current.Items[property.Name].Values.Add(new BucketItem.QueryCondition(targetValue, bucket.Relation)); } } } item = parts.Length > 1 ? bucket.Items[parts[1]] : bucket.Items[info.Name]; BucketItem leafItem; if (item.Child != null) { BucketItem i = item.GetActiveItem(); leafItem = new BucketItem { DeclaringType = i.DeclaringType, Name = i.Name, ProperyName = i.ProperyName, PropertyType = info.PropertyType, Unique = i.Unique, Child = i.Child, Container = i.Container }; leafItem.Values.Add(new BucketItem.QueryCondition(i.Value, bucket.Relation)); } else { // for getting the values directly. // add it to the bucket condition list. item.Values.Add(new BucketItem.QueryCondition(value, bucket.Relation)); leafItem = new BucketItem { DeclaringType = item.DeclaringType, Name = item.Name, ProperyName = item.ProperyName, PropertyType = info.PropertyType, MemberInfo = memberExpression.Member, Unique = item.Unique, Container = item.Container }; leafItem.Values.Add(new BucketItem.QueryCondition(value, bucket.Relation)); } bucket.CurrentTreeNode.Nodes.Add(new TreeNode.Node() { Value = leafItem }); }
private IDictionary<string, BucketItem> CreateItems(Type target) { PropertyInfo[] infos = target.GetProperties(); IDictionary<string, BucketItem> list = new Dictionary<string, BucketItem>(); foreach (PropertyInfo info in infos) { if (info.CanRead && info.CanWrite) { string fieldName = string.Empty; object[] arg = info.GetCustomAttributes(typeof (IgnoreAttribute), false); if (arg.Length == 0) { const bool visible = true; arg = info.GetCustomAttributes(typeof (NameAttribute), false); if (arg.Length > 0) { var fieldNameAttr = arg[0] as NameAttribute; if (fieldNameAttr != null) fieldName = fieldNameAttr.Name; } else { fieldName = info.Name; } arg = info.GetCustomAttributes(typeof (UniqueIdentifierAttribute), true); bool isUnique = arg.Length > 0; // only if not already added. if (!list.ContainsKey(info.Name)) { var newItem = new BucketItem(target, fieldName, info.Name, info.PropertyType, null, isUnique, BinaryOperator.Equal, visible) {Container = this}; list.Add(info.Name, newItem); } } } } return list; }