Skip to content

Commit

Permalink
EW
Browse files Browse the repository at this point in the history
  • Loading branch information
turecross321 committed Nov 4, 2023
1 parent fc3168a commit a80c7fb
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions SoundShapesServer/Extensions/RequestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,70 @@ public static (int, int, bool) GetPageData(this RequestContext context, bool des
foreach (PropertyInfo property in typeof(T).GetProperties())
{
FilterPropertyAttribute? attribute = property.GetCustomAttribute<FilterPropertyAttribute>();
if (attribute != null)
{
string? strValue = context.QueryString[attribute.ParameterName];
if (strValue == null)
continue;
if (attribute == null)
continue;

string? strValue = context.QueryString[attribute.ParameterName];
if (strValue == null)
continue;

object? value = null;
object? value = null;

// typeof can't be used in switch statements :/
if (property.PropertyType == typeof(GameUser))
{
value = database.GetUserWithId(strValue);
}
else if (property.PropertyType == typeof(GameAlbum))
{
value = database.GetAlbumWithId(strValue);
}
else if (property.PropertyType == typeof(bool?))
{
value = strValue.ToBool();
}
else if (property.PropertyType == typeof(string))
{
value = strValue;
}
else if (property.PropertyType == typeof(DateTimeOffset?))
{
if (DateTimeOffset.TryParse(strValue, out DateTimeOffset result)) value = result;
}
else if (property.PropertyType == typeof(int?))
{
value = strValue.ToInt();
}
else if (property.PropertyType == typeof(int[]))
{
List<int> list = new();
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (string numberStr in strValue.Split(","))
{
int? number = numberStr.ToInt();
if (number != null) list.Add((int)number);
}

value = Convert.ChangeType(list.ToArray(), property.PropertyType);
}
else if (property.PropertyType == typeof(GameUser[]))
// typeof can't be used in switch statements :/
if (property.PropertyType == typeof(GameUser))
{
value = database.GetUserWithId(strValue);
}
else if (property.PropertyType == typeof(GameAlbum))
{
value = database.GetAlbumWithId(strValue);
}
else if (property.PropertyType == typeof(bool?))
{
value = strValue.ToBool();
}
else if (property.PropertyType == typeof(string))
{
value = strValue;
}
else if (property.PropertyType == typeof(DateTimeOffset?))
{
if (DateTimeOffset.TryParse(strValue, out DateTimeOffset result)) value = result;
}
else if (property.PropertyType == typeof(int?))
{
value = strValue.ToInt();
}
else if (property.PropertyType == typeof(int[]))
{
List<int> list = new();
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (string numberStr in strValue.Split(","))
{
List<GameUser> list = new();
foreach (string id in strValue.Split(","))
{
GameUser? user = database.GetUserWithId(id);
if (user != null)
list.Add(user);
}

value = list.ToArray();
int? number = numberStr.ToInt();
if (number != null) list.Add((int)number);
}
else

value = Convert.ChangeType(list.ToArray(), property.PropertyType);
}
else if (property.PropertyType == typeof(GameUser[]))
{
List<GameUser> list = new();
foreach (string id in strValue.Split(","))
{
throw new ArgumentOutOfRangeException(property.PropertyType.Name + " filter is not supported");
GameUser? user = database.GetUserWithId(id);
if (user != null)
list.Add(user);
}

property.SetValue(instance, value);
value = list.ToArray();
}
else
{
throw new ArgumentOutOfRangeException(property.PropertyType.Name + " filter is not supported");
}

property.SetValue(instance, value);
}

return instance;
Expand Down

0 comments on commit a80c7fb

Please sign in to comment.