Fix: Rename Generic.CL folder to flat structure, update csproj and references
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Generic.Services;
|
||||
|
||||
public class AdvancedQueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
private string _preText = string.Empty;
|
||||
private string _afterText = string.Empty;
|
||||
private string _separator = "&";
|
||||
|
||||
public AdvancedQueryBuilder()
|
||||
{
|
||||
_builder = new StringBuilder();
|
||||
}
|
||||
|
||||
public AdvancedQueryBuilder AddPreText(string preText)
|
||||
{
|
||||
_preText = preText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdvancedQueryBuilder AddAfterText(string afterText)
|
||||
{
|
||||
_afterText = afterText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdvancedQueryBuilder AddSeprator(string separator)
|
||||
{
|
||||
_separator = separator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdvancedQueryBuilder AddModels(params object?[] models)
|
||||
{
|
||||
if (models == null)
|
||||
return this;
|
||||
|
||||
foreach (var model in models)
|
||||
{
|
||||
if (model == null)
|
||||
continue;
|
||||
|
||||
var properties = model.GetType().GetProperties();
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
var value = prop.GetValue(model)?.ToString();
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
AppendParameter(prop.Name.ToLower(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void AppendParameter(string key, string value)
|
||||
{
|
||||
if (_builder.Length > 0)
|
||||
_builder.Append(_separator);
|
||||
_builder.Append($"{Uri.EscapeDataString(key)}={Uri.EscapeDataString(value)}");
|
||||
}
|
||||
|
||||
public override string ToString() => $"{_preText}{_builder}{_afterText}";
|
||||
}
|
||||
Reference in New Issue
Block a user