Skip to content

Commit

Permalink
edited namespaces and added globalusing.
Browse files Browse the repository at this point in the history
  • Loading branch information
byerlikaya committed Dec 2, 2023
1 parent d8123cf commit 7b908aa
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 573 deletions.
19 changes: 8 additions & 11 deletions src/SmartWhere/Attributes/ComparativeWhereCaluseAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using SmartWhere.Enums;
namespace SmartWhere.Attributes;

namespace SmartWhere.Attributes
public class ComparativeWhereCaluseAttribute : WhereClauseAttribute
{
public class ComparativeWhereCaluseAttribute : WhereClauseAttribute
{
public ComparisonOperator ComparisonOperator { get; set; }
public ComparisonOperator ComparisonOperator { get; set; }

public ComparativeWhereCaluseAttribute(ComparisonOperator comparisonOperator, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(logicalOperator) => ComparisonOperator = comparisonOperator;
public ComparativeWhereCaluseAttribute(ComparisonOperator comparisonOperator, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(logicalOperator) => ComparisonOperator = comparisonOperator;

public ComparativeWhereCaluseAttribute(string propertyName, ComparisonOperator comparisonOperator, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(propertyName, logicalOperator) => ComparisonOperator = comparisonOperator;
}
}
public ComparativeWhereCaluseAttribute(string propertyName, ComparisonOperator comparisonOperator, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(propertyName, logicalOperator) => ComparisonOperator = comparisonOperator;
}
19 changes: 8 additions & 11 deletions src/SmartWhere/Attributes/TextualWhereClauseAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using SmartWhere.Enums;
namespace SmartWhere.Attributes;

namespace SmartWhere.Attributes
public class TextualWhereClauseAttribute : WhereClauseAttribute
{
public class TextualWhereClauseAttribute : WhereClauseAttribute
{
public StringMethod StringMethod { get; set; }
public StringMethod StringMethod { get; set; }

public TextualWhereClauseAttribute(StringMethod method, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(logicalOperator) => StringMethod = method;
public TextualWhereClauseAttribute(StringMethod method, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(logicalOperator) => StringMethod = method;

public TextualWhereClauseAttribute(string propertyName, StringMethod method, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(propertyName, logicalOperator) => StringMethod = method;
}
}
public TextualWhereClauseAttribute(string propertyName, StringMethod method, LogicalOperator logicalOperator = LogicalOperator.AND)
: base(propertyName, logicalOperator) => StringMethod = method;
}
26 changes: 11 additions & 15 deletions src/SmartWhere/Attributes/WhereClauseAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using SmartWhere.Enums;
using System;
namespace SmartWhere.Attributes;

namespace SmartWhere.Attributes
[AttributeUsage(AttributeTargets.Property)]
public class WhereClauseAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Property)]
public class WhereClauseAttribute : Attribute
{
public string PropertyName { get; set; }
public string PropertyName { get; set; }

public LogicalOperator LogicalOperator { get; set; }
public LogicalOperator LogicalOperator { get; set; }

public WhereClauseAttribute(LogicalOperator logicalOperator = LogicalOperator.AND) => LogicalOperator = logicalOperator;
public WhereClauseAttribute(LogicalOperator logicalOperator = LogicalOperator.AND) => LogicalOperator = logicalOperator;

public WhereClauseAttribute(string propertyName, LogicalOperator logicalOperator = LogicalOperator.AND)
{
PropertyName = propertyName;
LogicalOperator = logicalOperator;
}
public WhereClauseAttribute(string propertyName, LogicalOperator logicalOperator = LogicalOperator.AND)
{
PropertyName = propertyName;
LogicalOperator = logicalOperator;
}
}
}
11 changes: 4 additions & 7 deletions src/SmartWhere/Attributes/WhereClauseClassAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
namespace SmartWhere.Attributes;

namespace SmartWhere.Attributes
[AttributeUsage(AttributeTargets.Property)]
public class WhereClauseClassAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Property)]
public class WhereClauseClassAttribute : Attribute
{
}
}
}
29 changes: 14 additions & 15 deletions src/SmartWhere/Enums/ComparisonOperator.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace SmartWhere.Enums
namespace SmartWhere.Enums;

public enum ComparisonOperator
{
public enum ComparisonOperator
{
Equal,
NotEqual,
GreaterThan,
NotGreaterThan,
GreaterThanOrEqual,
NotGreaterThanOrEqual,
LessThan,
NotLessThan,
LessThanOrEqual,
NotLessThanOrEqual
}
}
Equal,
NotEqual,
GreaterThan,
NotGreaterThan,
GreaterThanOrEqual,
NotGreaterThanOrEqual,
LessThan,
NotLessThan,
LessThanOrEqual,
NotLessThanOrEqual
}
21 changes: 10 additions & 11 deletions src/SmartWhere/Enums/StringMethod.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
namespace SmartWhere.Enums
namespace SmartWhere.Enums;

public enum StringMethod
{
public enum StringMethod
{
Contains,
NotContains,
StartsWith,
NotStartsWith,
EndsWith,
NotEndsWith
}
}
Contains,
NotContains,
StartsWith,
NotStartsWith,
EndsWith,
NotEndsWith
}
45 changes: 20 additions & 25 deletions src/SmartWhere/Extensions/AttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
using SmartWhere.Attributes;
using SmartWhere.Enums;
using System.Reflection;
namespace SmartWhere.Extensions;

namespace SmartWhere.Extensions
internal static class AttributeExtensions
{
public static class AttributeExtensions
{
internal static WhereClauseAttribute GetWhereClauseAttribute(this MemberInfo memberInfo) =>
(WhereClauseAttribute)memberInfo.GetCustomAttribute(typeof(WhereClauseAttribute), false);
internal static WhereClauseAttribute GetWhereClauseAttribute(this MemberInfo memberInfo) =>
(WhereClauseAttribute)memberInfo.GetCustomAttribute(typeof(WhereClauseAttribute), false);

internal static WhereClauseClassAttribute GetWhereClauseClassAttribute(this MemberInfo memberInfo) =>
(WhereClauseClassAttribute)memberInfo.GetCustomAttribute(typeof(WhereClauseClassAttribute), false);
internal static WhereClauseClassAttribute GetWhereClauseClassAttribute(this MemberInfo memberInfo) =>
(WhereClauseClassAttribute)memberInfo.GetCustomAttribute(typeof(WhereClauseClassAttribute), false);

internal static MethodInfo MethodInfo(this TextualWhereClauseAttribute textualWhereClause)
internal static MethodInfo MethodInfo(this TextualWhereClauseAttribute textualWhereClause)
{
var methodName = textualWhereClause.StringMethod switch
{
var methodName = textualWhereClause.StringMethod switch
{
StringMethod.Contains => textualWhereClause.StringMethod.ToString(),
StringMethod.StartsWith => textualWhereClause.StringMethod.ToString(),
StringMethod.EndsWith => textualWhereClause.StringMethod.ToString(),
StringMethod.NotContains => nameof(StringMethod.Contains),
StringMethod.NotStartsWith => nameof(StringMethod.StartsWith),
StringMethod.NotEndsWith => nameof(StringMethod.EndsWith),
_ => nameof(StringMethod.Contains)
};
StringMethod.Contains => textualWhereClause.StringMethod.ToString(),
StringMethod.StartsWith => textualWhereClause.StringMethod.ToString(),
StringMethod.EndsWith => textualWhereClause.StringMethod.ToString(),
StringMethod.NotContains => nameof(StringMethod.Contains),
StringMethod.NotStartsWith => nameof(StringMethod.StartsWith),
StringMethod.NotEndsWith => nameof(StringMethod.EndsWith),
_ => nameof(StringMethod.Contains)
};

return typeof(string).GetMethod(methodName, new[] { typeof(string)
});
}
return typeof(string).GetMethod(methodName, new[] { typeof(string)
});
}
}
}
Loading

0 comments on commit 7b908aa

Please sign in to comment.