Skip to content

Commit

Permalink
Fixed search
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Nov 10, 2023
1 parent 0e91d95 commit 8defffb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h2>Loading...</h2>
<!-- https://metrica.yandex.com/dashboard?id=87711623 -->
<!-- Please create an issue on our repo if you have a better alternative! -->
<!-- https://github.com/BUTR/BUTR.Site.NexusMods -->
<script defer src="https://cdn.jsdelivr.net/gh/orestbida/[email protected]/dist/cookieconsent.min.js" integrity="sha256-H+Z1mZeulbIwdqtQq6Vgn6y6yr33+pzXlDd13s3dLh4=" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/gh/orestbida/[email protected]/dist/cookieconsent.min.js" integrity="sha384-Q979APNquWnMfwcI77qZm43RXhRv43xW3iUhlhInJ9mR1f8bsm7wUTvvBZfg85ef" crossorigin="anonymous"></script>
<script defer src="js/cookieconsent-init.js"></script>
<script type="text/plain" data-cookiecategory="metrics">
(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ private async IAsyncEnumerable<ModuleUpdate> GetModuleUpdatesForBannerlordAsync(
var moduleIds = crashReport.Modules.Where(x => !x.IsOfficial && string.IsNullOrEmpty(x.Url) && string.IsNullOrEmpty(x.UpdateInfo))
.Select(x => ModuleId.From(x.Id)).ToArray();
var nexusModsIds = crashReport.Modules.Where(x => !x.IsOfficial && !string.IsNullOrEmpty(x.Url))
.Select(x => NexusModsModId.From(NexusModsUtils.TryParse(x.Url, out _, out var id) ? (int) id : -1))
.Where(x => x != -1).ToArray();
.Select(x => NexusModsModId.TryParseUrl(x.Url, out var modId) ? modId : NexusModsModId.None)
.Where(x => x != NexusModsModId.None).ToArray();
var nexusModsIds2 = crashReport.Modules.Where(x => !x.IsOfficial && !string.IsNullOrEmpty(x.Url))
.Select(x => new { ModuelId = ModuleId.From(x.Id), NexusModsId = NexusModsModId.From(NexusModsUtils.TryParse(x.Url, out _, out var id) ? (int) id : -1) })
.Where(x => x.NexusModsId != -1).ToArray();
.Where(x => x.NexusModsId != NexusModsModId.None).ToArray();
var updateInfos = crashReport.Modules.Where(x => !x.IsOfficial && !string.IsNullOrEmpty(x.UpdateInfo))
.Select(x => new { ModuleId = ModuleId.From(x.Id), x.UpdateInfo }).ToArray();
var moduleIdVersions = crashReport.Modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,28 @@ private static Expression RobustEquals(MemberExpression prop, ConstantExpression

private static Expression GetContainsMethodCallExpression(MemberExpression prop, ConstantExpression constant)
{
if (prop.Type == typeof(string)) // Check if it's convertible to string
var type = Nullable.GetUnderlyingType(constant.Type) ?? constant.Type;

if (type == typeof(string)) // Check if it's convertible to string
return Expression.Call(prop, _stringContainsMethod, AsString(constant));
else if (prop.Type.GetInterfaces().Contains(typeof(IDictionary)))
else if (TypeDescriptor.GetConverter(type) is { } typeConverter && typeConverter.CanConvertTo(typeof(string)))
return Expression.Call(AsString(prop), _stringContainsMethod, AsString(constant));
else if (type.GetInterfaces().Contains(typeof(IDictionary)))
return Expression.Or(Expression.Call(prop, _dictionaryContainsKeyMethod, AsString(constant)), Expression.Call(prop, _dictionaryContainsValueMethod, AsString(constant)));
else if (prop.Type.GetInterfaces().Contains(typeof(IEnumerable)))
else if (type.GetInterfaces().Contains(typeof(IEnumerable)))
return Expression.Call(_enumerableContainsMethod, prop, AsString(constant));

throw new NotImplementedException($"{prop.Type} contains is not implemented.");
throw new NotImplementedException($"{type} contains is not implemented.");
}

private static Expression AsString(Expression constant)
{
if (constant.Type == typeof(string))
var type = Nullable.GetUnderlyingType(constant.Type) ?? constant.Type;

if (type == typeof(string))
return constant;

if (TypeDescriptor.GetConverter(constant.Type) is { } typeConverter && typeConverter.CanConvertTo(typeof(string)))
if (TypeDescriptor.GetConverter(type) is { } typeConverter && typeConverter.CanConvertTo(typeof(string)))
return Expression.Convert(constant, typeof(string));

var convertedExpr = Expression.Convert(constant, typeof(object));
Expand Down

0 comments on commit 8defffb

Please sign in to comment.