Skip to content

Commit

Permalink
Fix for Issue Biarity#19
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnmbond committed May 14, 2018
1 parent afbd41e commit 204a1b5
Show file tree
Hide file tree
Showing 39 changed files with 361 additions and 486 deletions.
40 changes: 40 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
root = true

# All files
[*]
indent_style = space
trim_trailing_whitespace = true

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
end_of_line = crlf

# Xml files
[*.xml]
indent_size = 2

# Dotnet code style
[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true

# Avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Naming conventions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Classes, structs, methods, enums, events, properties, namespaces, delegates must be PascalCase
dotnet_naming_rule.general_naming.severity = suggestion
dotnet_naming_rule.general_naming.symbols = general
dotnet_naming_rule.general_naming.style = pascal_case_style
dotnet_naming_symbols.general.applicable_kinds = class,struct,enum,property,method,event,namespace,delegate
dotnet_naming_symbols.general.applicable_accessibilities = *
7 changes: 6 additions & 1 deletion Sieve.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sieve", "Sieve\Sieve.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SieveTests", "SieveTests\SieveTests.csproj", "{8043D264-42A0-4275-97A1-46400C02E37E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SieveUnitTests", "SieveUnitTests\SieveUnitTests.csproj", "{21C3082D-F40E-457F-BE2E-AA099E19E199}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SieveUnitTests", "SieveUnitTests\SieveUnitTests.csproj", "{21C3082D-F40E-457F-BE2E-AA099E19E199}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{904F25A9-5CBD-42AE-8422-ADAB98F4B4B7}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 1 addition & 3 deletions Sieve/Attributes/SieveAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Sieve.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sieve.Attributes
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class SieveAttribute : Attribute, ISievePropertyMetadata
{
/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions Sieve/Exceptions/SieveException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sieve.Exceptions
{
Expand All @@ -13,5 +11,13 @@ public SieveException(string message) : base(message)
public SieveException(string message, Exception innerException) : base(message, innerException)
{
}

public SieveException()
{
}

protected SieveException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
27 changes: 20 additions & 7 deletions Sieve/Exceptions/SieveIncompatibleMethodException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sieve.Exceptions
{
Expand All @@ -10,12 +8,11 @@ public class SieveIncompatibleMethodException : SieveException
public Type ExpectedType { get; protected set; }
public Type ActualType { get; protected set; }


public SieveIncompatibleMethodException(
string methodName,
string methodName,
Type expectedType,
Type actualType,
string message)
string message)
: base(message)
{
MethodName = methodName;
Expand All @@ -24,16 +21,32 @@ public SieveIncompatibleMethodException(
}

public SieveIncompatibleMethodException(
string methodName,
string methodName,
Type expectedType,
Type actualType,
string message,
Exception innerException)
Exception innerException)
: base(message, innerException)
{
MethodName = methodName;
ExpectedType = expectedType;
ActualType = actualType;
}

public SieveIncompatibleMethodException(string message) : base(message)
{
}

public SieveIncompatibleMethodException(string message, Exception innerException) : base(message, innerException)
{
}

public SieveIncompatibleMethodException()
{
}

protected SieveIncompatibleMethodException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
20 changes: 17 additions & 3 deletions Sieve/Exceptions/SieveMethodNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sieve.Exceptions
{
public class SieveMethodNotFoundException : SieveException
{
public string MethodName { get; protected set; }

public SieveMethodNotFoundException(string methodName, string message) : base (message)
public SieveMethodNotFoundException(string methodName, string message) : base(message)
{
MethodName = methodName;
}
Expand All @@ -17,5 +15,21 @@ public SieveMethodNotFoundException(string methodName, string message, Exception
{
MethodName = methodName;
}

public SieveMethodNotFoundException(string message) : base(message)
{
}

public SieveMethodNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}

public SieveMethodNotFoundException()
{
}

protected SieveMethodNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
6 changes: 2 additions & 4 deletions Sieve/Extensions/OrderByDynamic.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Sieve.Extensions
{
public static partial class LinqExtentions
public static partial class LinqExtentions
{
public static IQueryable<TEntity> OrderByDynamic<TEntity>(this IQueryable<TEntity> source, string orderByProperty,
bool desc, bool useThenBy)
{
string command = desc ?
string command = desc ?
( useThenBy ? "ThenByDescending" : "OrderByDescending") :
( useThenBy ? "ThenBy" : "OrderBy");
var type = typeof(TEntity);
Expand Down
8 changes: 2 additions & 6 deletions Sieve/Models/FilterOperator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sieve.Models
namespace Sieve.Models
{
public enum FilterOperator
public enum FilterOperator
{
Equals,
NotEquals,
Expand Down
109 changes: 37 additions & 72 deletions Sieve/Models/FilterTerm.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Linq;

namespace Sieve.Models
{
public class FilterTerm : IFilterTerm
{
private string _filter;
private string[] operators = new string[] {
private static readonly string[] Operators = new string[] {
"==*",
"@=*",
"_=*",
Expand All @@ -24,82 +21,50 @@ public class FilterTerm : IFilterTerm

public FilterTerm(string filter)
{
_filter = filter;
var filterSplits = filter.Split(Operators, StringSplitOptions.RemoveEmptyEntries).Select(t => t.Trim()).ToArray();
Names = filterSplits[0].Split('|').Select(t => t.Trim()).ToArray();
Value = filterSplits.Length > 1 ? filterSplits[1] : null;
Operator = Array.Find(Operators, o => filter.Contains(o)) ?? "==";
OperatorParsed = GetOperatorParsed(Operator);
OperatorIsCaseInsensitive = Operator.Contains("*");
}

public string Name
{
get
{
var tokens = _filter.Split(operators, StringSplitOptions.RemoveEmptyEntries);
return tokens.Length > 0 ? tokens[0].Trim() : "";

}
}
public string[] Names { get; }

public string Operator
{
get
{
foreach (var op in operators)
{
if (_filter.IndexOf(op) != -1)
{
return op;
}
}

// Custom operators not supported
// var tokens = _filter.Split(' ');
// return tokens.Length > 2 ? tokens[1] : "";
return "";
}
}
public FilterOperator OperatorParsed { get; }

public string Value {
get
{
var tokens = _filter.Split(operators, StringSplitOptions.RemoveEmptyEntries);
return tokens.Length > 1 ? tokens[1].Trim() : null;
}
}
public string Value { get; }

public FilterOperator OperatorParsed {
get
{
switch (Operator.Trim().ToLower())
{
case "==":
case "==*":
return FilterOperator.Equals;
case "!=":
return FilterOperator.NotEquals;
case "<":
return FilterOperator.LessThan;
case ">":
return FilterOperator.GreaterThan;
case ">=":
return FilterOperator.GreaterThanOrEqualTo;
case "<=":
return FilterOperator.LessThanOrEqualTo;
case "@=":
case "@=*":
return FilterOperator.Contains;
case "_=":
case "_=*":
return FilterOperator.StartsWith;
default:
return FilterOperator.Equals;
}
}
}
public string Operator { get; }

public bool OperatorIsCaseInsensitive
private FilterOperator GetOperatorParsed(string Operator)
{
get
switch (Operator.Trim().ToLower())
{
return Operator.Contains("*");
case "==":
case "==*":
return FilterOperator.Equals;
case "!=":
return FilterOperator.NotEquals;
case "<":
return FilterOperator.LessThan;
case ">":
return FilterOperator.GreaterThan;
case ">=":
return FilterOperator.GreaterThanOrEqualTo;
case "<=":
return FilterOperator.LessThanOrEqualTo;
case "@=":
case "@=*":
return FilterOperator.Contains;
case "_=":
case "_=*":
return FilterOperator.StartsWith;
default:
return FilterOperator.Equals;
}
}

public bool OperatorIsCaseInsensitive { get; }
}
}
9 changes: 2 additions & 7 deletions Sieve/Models/IFilterTerm.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace Sieve.Models
namespace Sieve.Models
{
public interface IFilterTerm
{
string Name { get; }
string[] Names { get; }
string Operator { get; }
bool OperatorIsCaseInsensitive { get; }
FilterOperator OperatorParsed { get; }
Expand Down
11 changes: 4 additions & 7 deletions Sieve/Models/ISieveModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Collections.Generic;

namespace Sieve.Models
{
public interface ISieveModel<TFilterTerm, TSortTerm>
public interface ISieveModel<TFilterTerm, TSortTerm>
where TFilterTerm : IFilterTerm
where TSortTerm : ISortTerm
{
string Filters { get; set; }

string Sorts { get; set; }

int? Page { get; set; }

int? PageSize { get; set; }

List<TFilterTerm> FiltersParsed { get; }
Expand Down
Loading

0 comments on commit 204a1b5

Please sign in to comment.