Skip to content

Commit 2013f67

Browse files
committed
Updating to NetStandardPolyfills v1.2, removing dependency on System.Reflection.TypeExtensions
1 parent 748c523 commit 2013f67

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

ReadableExpressions.UnitTests/ReadableExpressions.UnitTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.0.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
39-
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.0.0\lib\net40\AgileObjects.NetStandardPolyfills.dll</HintPath>
38+
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.2.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
39+
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.2.0\lib\net40\AgileObjects.NetStandardPolyfills.dll</HintPath>
4040
</Reference>
4141
<Reference Include="Microsoft.CSharp" />
4242
<Reference Include="System" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AgileObjects.NetStandardPolyfills" version="1.0.0" targetFramework="net45" />
3+
<package id="AgileObjects.NetStandardPolyfills" version="1.2.0" targetFramework="net45" />
44
</packages>

ReadableExpressions/Extensions/PublicTypeExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
#if NET_STANDARD
7-
using System.Reflection;
8-
#endif
96
using NetStandardPolyfills;
107

118
/// <summary>
@@ -55,7 +52,7 @@ public static string GetFriendlyName(this Type type)
5552

5653
private static string GetGenericTypeName(Type genericType)
5754
{
58-
var typeGenericTypeArguments = genericType.GetGenericArguments();
55+
var typeGenericTypeArguments = genericType.GetGenericTypeArguments();
5956

6057
if (!genericType.IsNested)
6158
{

ReadableExpressions/ReadableExpressions.csproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@
2424
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
2525
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
2626
<RootNamespace>AgileObjects.ReadableExpressions</RootNamespace>
27-
<AssemblyVersion>1.9.5.0</AssemblyVersion>
28-
<FileVersion>1.9.5.0</FileVersion>
29-
<Version>1.9.5</Version>
27+
<AssemblyVersion>1.9.6.0</AssemblyVersion>
28+
<FileVersion>1.9.6.0</FileVersion>
29+
<Version>1.9.6</Version>
3030
<Company>AgileObjects Ltd</Company>
3131
</PropertyGroup>
3232

33-
<ItemGroup>
34-
<PackageReference Include="AgileObjects.NetStandardPolyfills" Version="1.0.0" />
35-
</ItemGroup>
36-
3733
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
3834
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
39-
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
4035
</ItemGroup>
4136

4237
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
@@ -48,4 +43,8 @@
4843
<Reference Include="Microsoft.CSharp" />
4944
</ItemGroup>
5045

46+
<ItemGroup>
47+
<PackageReference Include="AgileObjects.NetStandardPolyfills" Version="1.2.0" />
48+
</ItemGroup>
49+
5150
</Project>

ReadableExpressions/Translators/ConstantExpressionTranslator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ namespace AgileObjects.ReadableExpressions.Translators
33
using System;
44
using System.Globalization;
55
using System.Linq.Expressions;
6-
#if NET_STANDARD
7-
using System.Reflection;
8-
#endif
96
using System.Text.RegularExpressions;
107
using Extensions;
118
using NetStandardPolyfills;
@@ -230,7 +227,7 @@ private static string FormatNumeric(float value)
230227

231228
private static bool IsType(ConstantExpression constant, out string translation)
232229
{
233-
if (typeof(Type).IsAssignableFrom(constant.Type))
230+
if (constant.Type.IsAssignableTo(typeof(Type)))
234231
{
235232
translation = $"typeof({((Type)constant.Value).GetFriendlyName()})";
236233
return true;

ReadableExpressions/Translators/DynamicExpressionTranslator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace AgileObjects.ReadableExpressions.Translators
66
using System.Linq.Expressions;
77
using System.Reflection;
88
using System.Text.RegularExpressions;
9+
using NetStandardPolyfills;
910

1011
internal class DynamicExpressionTranslator : ExpressionTranslatorBase
1112
{
@@ -164,7 +165,7 @@ protected override bool DoTranslate(
164165
var subjectObject = dynamicExpression.Arguments.First();
165166
var subject = context.Translate(subjectObject);
166167
var methodName = match.Groups["MethodName"].Value;
167-
var method = subjectObject.Type.GetMethod(methodName);
168+
var method = subjectObject.Type.GetPublicMethod(methodName);
168169
var methodArguments = dynamicExpression.Arguments.Skip(1).ToArray();
169170

170171
var methodInfo = GetMethodInfo(

ReadableExpressions/Translators/MethodCallExpressionTranslator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private static void RemoveSuppliedGenericTypeParameters(
167167

168168
if (type.IsGenericType())
169169
{
170-
RemoveSuppliedGenericTypeParameters(type.GetGenericArguments(), genericParameterTypes);
170+
RemoveSuppliedGenericTypeParameters(type.GetGenericTypeArguments(), genericParameterTypes);
171171
}
172172
}
173173
}
@@ -242,7 +242,7 @@ public override string Translate(Expression expression, TranslationContext conte
242242
invocationSubject = invocationSubject.WithSurroundingParentheses();
243243
}
244244

245-
var invocationMethod = invocation.Expression.Type.GetMethod("Invoke");
245+
var invocationMethod = invocation.Expression.Type.GetPublicInstanceMethod("Invoke");
246246

247247
return _methodCallTranslator.Invoke(
248248
invocationSubject,
@@ -270,8 +270,8 @@ private static bool IsIndexedPropertyAccess(Expression expression)
270270
var property = methodCall
271271
.Object?
272272
.Type
273-
.GetProperties()
274-
.FirstOrDefault(p => p.GetAccessors().Contains(methodCall.Method));
273+
.GetPublicInstanceProperties()
274+
.FirstOrDefault(p => p.IsIndexer() && p.GetAccessors().Contains(methodCall.Method));
275275

276276
if (property == null)
277277
{

0 commit comments

Comments
 (0)