Skip to content

Commit

Permalink
fix WCF hositing build
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Svensson committed Jan 25, 2024
1 parent 542ccca commit 7081835
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<tags>WCF RIA Services RIAServices Server aspnet OpenRiaServices</tags>
<dependencies>
<group targetFramework="net472">
<dependency id="System.Memory" version="4.5.5"/>
<dependency id="OpenRiaServices.Server" version="$version$"/>
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0"/>
</group>
Expand All @@ -33,4 +34,4 @@
<file src="..\..\src\bin\Release\net472\OpenRiaServices.Hosting.Wcf.pdb" target="lib\net472\OpenRiaServices.Hosting.Wcf.pdb" />
<file src="..\..\src\bin\Release\net472\OpenRiaServices.Hosting.Wcf.xml" target="lib\net472\OpenRiaServices.Hosting.Wcf.xml" />
</files>
</package>
</package>
29 changes: 27 additions & 2 deletions src/OpenRiaServices.Hosting.Wcf/Framework/Linq/DynamicQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
using System.Globalization;
using System.Linq.Expressions;
using System.Reflection;
using System;

namespace System.Linq.Dynamic
{
#if NETFRAMEWORK
static class StringExtensions
{
static public string Slice(this string str, int startIndex, int length)
=> str.Substring(startIndex, length);
}
#endif

internal static class DynamicQueryable
{
public static IQueryable Where(this IQueryable source, string predicate, QueryResolver queryResolver)
Expand Down Expand Up @@ -1460,12 +1469,14 @@ Expression PromoteExpression(Expression expr, Type type, bool exact)
value = ParseNumber(text.Span, target);
break;
case TypeCode.String:
#if !NETFRAMEWORK
if (ce.Value is string str)
{
// We parsed as text but wanted it as something else, probaly an enum
value = ParseEnum(str, target);
}
else
#endif
{
// We parsed as text but wanted it as something else, probaly an enum
value = ParseEnum(text.Span, target);
Expand All @@ -1486,8 +1497,14 @@ Expression PromoteExpression(Expression expr, Type type, bool exact)
return null;
}

#if NETFRAMEWORK
static object ParseNumber(ReadOnlySpan<char> span, Type type)
{
string text = span.ToString();
#else
static object ParseNumber(ReadOnlySpan<char> text, Type type)
{
#endif
switch (Type.GetTypeCode(GetNonNullableType(type)))
{
case TypeCode.SByte:
Expand Down Expand Up @@ -1556,8 +1573,16 @@ static object ParseEnum(ReadOnlySpan<char> name, Type type)
#if NET
Enum.TryParse(type, name, ignoreCase: true, out var result);
#else
object result;
try
{
result = Enum.Parse(type, name.ToString(), ignoreCase: true);

Enum.TryParse(type, name.ToString(), ignoreCase: true, out var result);
}
catch (Exception)
{
result = null;
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
#endif
return result;
}
Expand Down Expand Up @@ -2093,7 +2118,7 @@ bool TokenIdentifierIs(string id)
Token token = this.token;
return _tokenId == TokenId.Identifier
&& token.length == id.Length
&& GetText(token).Equals(id, StringComparison.OrdinalIgnoreCase);
&& GetText(token).Equals(id.AsSpan(), StringComparison.OrdinalIgnoreCase);
}

string GetIdentifier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\OpenRiaServices.Client.Web\Framework\Data\Behaviors\MessageUtility.cs" Link="WCF\Behaviors\MessageUtility.cs" />
Expand Down

0 comments on commit 7081835

Please sign in to comment.