Skip to content

Commit 9888d0d

Browse files
authored
Xamarin fix Enum (#481)
* repro * fix code
1 parent 712802a commit 9888d0d

152 files changed

Lines changed: 8044 additions & 125 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

System.Linq.Dynamic.Core.sln

Lines changed: 115 additions & 74 deletions
Large diffs are not rendered by default.

src-android/TestSLDC/MainPage.xaml.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected Type ResolveTypeBySimpleName([NotNull] IEnumerable<Assembly> assemblie
7676
return null;
7777
}
7878

79-
#if (WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
79+
#if (WINDOWS_APP || UAP10_0 || NETSTANDARD)
8080
/// <summary>
8181
/// Gets the assembly types annotated with <see cref="DynamicLinqTypeAttribute"/> in an Exception friendly way.
8282
/// </summary>

src/System.Linq.Dynamic.Core/DefaultAssemblyHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Assembly[] GetAssemblies()
2929
return assemblies.ToArray();
3030
}
3131

32-
#elif DOTNET5_1 || WINDOWS_APP || UAP10_0 || NETSTANDARD || WPSL
32+
#elif WINDOWS_APP || UAP10_0 || NETSTANDARD || WPSL
3333
public Assembly[] GetAssemblies()
3434
{
3535
throw new NotSupportedException();

src/System.Linq.Dynamic.Core/DynamicClassFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public static class DynamicClassFactory
3333
private static readonly CustomAttributeBuilder DebuggerHiddenAttributeBuilder = new CustomAttributeBuilder(typeof(DebuggerHiddenAttribute).GetConstructor(EmptyTypes), new object[0]);
3434

3535
private static readonly ConstructorInfo ObjectCtor = typeof(object).GetConstructor(EmptyTypes);
36-
#if WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD
36+
#if WINDOWS_APP || UAP10_0 || NETSTANDARD
3737
private static readonly MethodInfo ObjectToString = typeof(object).GetMethod("ToString", BindingFlags.Instance | BindingFlags.Public);
3838
#else
3939
private static readonly MethodInfo ObjectToString = typeof(object).GetMethod("ToString", BindingFlags.Instance | BindingFlags.Public, null, EmptyTypes, null);
4040
#endif
4141

4242
private static readonly ConstructorInfo StringBuilderCtor = typeof(StringBuilder).GetConstructor(EmptyTypes);
43-
#if WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD
43+
#if WINDOWS_APP || UAP10_0 || NETSTANDARD
4444
private static readonly MethodInfo StringBuilderAppendString = typeof(StringBuilder).GetMethod("Append", new[] { typeof(string) });
4545
private static readonly MethodInfo StringBuilderAppendObject = typeof(StringBuilder).GetMethod("Append", new[] { typeof(object) });
4646
#else
@@ -50,7 +50,7 @@ public static class DynamicClassFactory
5050

5151
private static readonly Type EqualityComparer = typeof(EqualityComparer<>);
5252
private static readonly Type EqualityComparerGenericArgument = EqualityComparer.GetGenericArguments()[0];
53-
#if WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD
53+
#if WINDOWS_APP || UAP10_0 || NETSTANDARD
5454
private static readonly MethodInfo EqualityComparerDefault = EqualityComparer.GetMethod("get_Default", BindingFlags.Static | BindingFlags.Public);
5555
private static readonly MethodInfo EqualityComparerEquals = EqualityComparer.GetMethod("Equals", new[] { EqualityComparerGenericArgument, EqualityComparerGenericArgument });
5656
private static readonly MethodInfo EqualityComparerGetHashCode = EqualityComparer.GetMethod("GetHashCode", new[] { EqualityComparerGenericArgument });

src/System.Linq.Dynamic.Core/Exceptions/ParseException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Globalization;
22

3-
#if !(SILVERLIGHT || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD || PORTABLE || WPSL)
3+
#if !(SILVERLIGHT || WINDOWS_APP || UAP10_0 || NETSTANDARD || PORTABLE || WPSL)
44
using System.Runtime.Serialization;
55
#endif
66

@@ -9,7 +9,7 @@ namespace System.Linq.Dynamic.Core.Exceptions
99
/// <summary>
1010
/// Represents errors that occur while parsing dynamic linq string expressions.
1111
/// </summary>
12-
#if !(SILVERLIGHT || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD || PORTABLE || WPSL || NETSTANDARD2_0)
12+
#if !(SILVERLIGHT || WINDOWS_APP || UAP10_0 || NETSTANDARD || PORTABLE || WPSL || NETSTANDARD2_0)
1313
[Serializable]
1414
#endif
1515
public sealed class ParseException : Exception
@@ -39,7 +39,7 @@ public override string ToString()
3939
return string.Format(CultureInfo.CurrentCulture, Res.ParseExceptionFormat, Message, Position);
4040
}
4141

42-
#if !(SILVERLIGHT || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD || PORTABLE || WPSL || NETSTANDARD2_0)
42+
#if !(SILVERLIGHT || WINDOWS_APP || UAP10_0 || NETSTANDARD || PORTABLE || WPSL || NETSTANDARD2_0)
4343
ParseException(SerializationInfo info, StreamingContext context)
4444
: base(info, context)
4545
{

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ static Exception IncompatibleOperandsError(string opName, Expression left, Expre
20642064

20652065
static MemberInfo FindPropertyOrField(Type type, string memberName, bool staticAccess, ParsingConfig ParsingConfig)
20662066
{
2067-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
2067+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
20682068
BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly | (staticAccess ? BindingFlags.Static : BindingFlags.Instance);
20692069
foreach (Type t in TypeHelper.GetSelfAndBaseTypes(type))
20702070
{

src/System.Linq.Dynamic.Core/Parser/ExpressionPromoter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public virtual Expression Promote(Expression expr, Type type, bool exact, bool c
4343
Type target = TypeHelper.GetNonNullableType(type);
4444
object value = null;
4545

46-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
46+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
4747
switch (Type.GetTypeCode(ce.Type))
4848
{
4949
case TypeCode.Int32:
@@ -70,12 +70,14 @@ public virtual Expression Promote(Expression expr, Type type, bool exact, bool c
7070
#else
7171
if (ce.Type == typeof(int) || ce.Type == typeof(uint) || ce.Type == typeof(long) || ce.Type == typeof(ulong))
7272
{
73-
value = _numberParser.ParseNumber(text, target);
74-
75-
// Make sure an enum value stays an enum value
73+
// If target is an enum value, just use the Value from the ConstantExpression
7674
if (target.GetTypeInfo().IsEnum)
7775
{
78-
value = Enum.ToObject(target, value);
76+
value = Enum.ToObject(target, ce.Value);
77+
}
78+
else
79+
{
80+
value = _numberParser.ParseNumber(text, target);
7981
}
8082
}
8183
else if (ce.Type == typeof(double))

src/System.Linq.Dynamic.Core/Parser/NumberParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public object ParseNumber(string text, Type type)
2525
{
2626
try
2727
{
28-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
28+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
2929
switch (Type.GetTypeCode(TypeHelper.GetNonNullableType(type)))
3030
{
3131
case TypeCode.SByte:

src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal static class PredefinedTypesHelper
4949

5050
static PredefinedTypesHelper()
5151
{
52-
#if !(NET35 || SILVERLIGHT || NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
52+
#if !(NET35 || SILVERLIGHT || NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
5353
//System.Data.Entity is always here, so overwrite short name of it with EntityFramework if EntityFramework is found.
5454
//EF5(or 4.x??), System.Data.Objects.DataClasses.EdmFunctionAttribute
5555
//There is also an System.Data.Entity, Version=3.5.0.0, but no Functions.

0 commit comments

Comments
 (0)