creating anonymous types :)

This commit is contained in:
David Lebée
2018-03-08 23:22:12 -06:00
parent 64d60b6942
commit 7278dea56d
13 changed files with 132 additions and 45 deletions
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace PoweredSoft.DynamicLinq.Fluent
{
public class GroupBuilder
{
public List<(string path, string propertyName)> Parts { get; set; } = new List<(string path, string propertyName)>();
public bool Empty => !Parts.Any();
public GroupBuilder Path(string path, string propertyName = null)
{
if (propertyName == null)
{
var name = path;
if (name.Contains("."))
{
var parts = name.Split('.');
name = parts[parts.Length - 1]; // the last one.
}
if (Parts.Any(t => t.propertyName == name))
throw new Exception($"{name} is already taken by another group part, you can specify a property name instead to resolve this issue");
propertyName = name;
}
Parts.Add((path, propertyName));
return this;
}
}
}