Skip to content

Commit 9888d0d

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

File tree

152 files changed

+8044
-125
lines changed

Some content is hidden

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

152 files changed

+8044
-125
lines changed

System.Linq.Dynamic.Core.sln

+115-74
Large diffs are not rendered by default.

src-android/TestSLDC/MainPage.xaml.cs

-27
This file was deleted.

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

+1-1
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

+1-1
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

+3-3
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

+3-3
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

+1-1
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

+7-5
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

+1-1
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

+1-1
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.

src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public bool ContainsMethod(Type type, string methodName, bool staticAccess, Expr
2727

2828
public int FindMethod(Type type, string methodName, bool staticAccess, ref Expression instance, ref Expression[] args, out MethodBase method)
2929
{
30-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
30+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
3131
BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly | (staticAccess ? BindingFlags.Static : BindingFlags.Instance);
3232
foreach (Type t in SelfAndBaseTypes(type))
3333
{
@@ -115,7 +115,7 @@ public int FindIndexer(Type type, Expression[] args, out MethodBase method)
115115
if (members.Length != 0)
116116
{
117117
IEnumerable<MethodBase> methods = members.OfType<PropertyInfo>().
118-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
118+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
119119
Select(p => (MethodBase)p.GetGetMethod()).
120120
Where(m => m != null);
121121
#else

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static Type FindGenericType(Type generic, Type type)
3232

3333
public static bool IsCompatibleWith(Type source, Type target)
3434
{
35-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
35+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
3636
if (source == target)
3737
{
3838
return true;
@@ -288,7 +288,7 @@ private static int GetNumericTypeKind(Type type)
288288
{
289289
type = GetNonNullableType(type);
290290

291-
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
291+
#if !(NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD)
292292
if (type.GetTypeInfo().IsEnum)
293293
{
294294
return 0;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public IDynamicLinkCustomTypeProvider CustomTypeProvider
4646
{
4747
get
4848
{
49-
#if !(DOTNET5_1 || WINDOWS_APP || UAP10_0 || NETSTANDARD)
49+
#if !( WINDOWS_APP || UAP10_0 || NETSTANDARD)
5050
// only use DefaultDynamicLinqCustomTypeProvider for full .NET Framework and NET Core App 2.x
5151
return _customTypeProvider ?? (_customTypeProvider = new DefaultDynamicLinqCustomTypeProvider());
5252
#else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{CE0965F5-C4DD-4CAB-94C6-FE260775D2B3}</ProjectGuid>
7+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>ExpressionSample.Droid</RootNamespace>
11+
<AssemblyName>ExpressionSample.Android</AssemblyName>
12+
<Deterministic>True</Deterministic>
13+
<AndroidApplication>True</AndroidApplication>
14+
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
15+
<AndroidResgenClass>Resource</AndroidResgenClass>
16+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
17+
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
18+
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
19+
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
20+
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
21+
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
22+
<AndroidUseAapt2>true</AndroidUseAapt2>
23+
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
24+
<NuGetPackageImportStamp>
25+
</NuGetPackageImportStamp>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
28+
<DebugSymbols>true</DebugSymbols>
29+
<DebugType>portable</DebugType>
30+
<Optimize>false</Optimize>
31+
<OutputPath>bin\Debug</OutputPath>
32+
<DefineConstants>DEBUG;</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
<AndroidLinkMode>None</AndroidLinkMode>
36+
</PropertyGroup>
37+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
38+
<DebugSymbols>true</DebugSymbols>
39+
<DebugType>portable</DebugType>
40+
<Optimize>true</Optimize>
41+
<OutputPath>bin\Release</OutputPath>
42+
<ErrorReport>prompt</ErrorReport>
43+
<WarningLevel>4</WarningLevel>
44+
<AndroidManagedSymbols>true</AndroidManagedSymbols>
45+
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Reference Include="Mono.Android" />
49+
<Reference Include="System" />
50+
<Reference Include="System.Core" />
51+
<Reference Include="System.Xml.Linq" />
52+
<Reference Include="System.Xml" />
53+
<Reference Include="System.Numerics" />
54+
<Reference Include="System.Numerics.Vectors" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1451" />
58+
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Compile Include="MainActivity.cs" />
62+
<Compile Include="Resources\Resource.designer.cs" />
63+
<Compile Include="Properties\AssemblyInfo.cs" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<None Include="Resources\AboutResources.txt" />
67+
<None Include="Assets\AboutAssets.txt" />
68+
<None Include="Properties\AndroidManifest.xml" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<AndroidResource Include="Resources\layout\Tabbar.xml" />
72+
<AndroidResource Include="Resources\layout\Toolbar.xml" />
73+
<AndroidResource Include="Resources\values\styles.xml" />
74+
<AndroidResource Include="Resources\values\colors.xml" />
75+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
76+
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
77+
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
78+
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
79+
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
80+
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
81+
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
82+
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
83+
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
84+
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
85+
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
86+
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
87+
</ItemGroup>
88+
<ItemGroup>
89+
<Folder Include="Resources\drawable\" />
90+
</ItemGroup>
91+
<ItemGroup>
92+
<ProjectReference Include="..\ExpressionSample\ExpressionSample.csproj">
93+
<Project>{2B1797B7-A3CB-4405-A7D1-F44C378EBA4D}</Project>
94+
<Name>ExpressionSample</Name>
95+
</ProjectReference>
96+
</ItemGroup>
97+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
98+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content.PM;
5+
using Android.Runtime;
6+
using Android.Views;
7+
using Android.Widget;
8+
using Android.OS;
9+
10+
namespace ExpressionSample.Droid
11+
{
12+
[Activity(Label = "ExpressionSample", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
13+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
14+
{
15+
protected override void OnCreate(Bundle savedInstanceState)
16+
{
17+
TabLayoutResource = Resource.Layout.Tabbar;
18+
ToolbarResource = Resource.Layout.Toolbar;
19+
20+
base.OnCreate(savedInstanceState);
21+
22+
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
23+
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
24+
LoadApplication(new App());
25+
}
26+
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
27+
{
28+
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
29+
30+
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.expressionsample">
3+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
4+
<application android:label="ExpressionSample.Android" android:theme="@style/MainTheme"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("ExpressionSample.Android")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("ExpressionSample.Android")]
14+
[assembly: AssemblyCopyright("Copyright © 2014")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
[assembly: AssemblyVersion("1.0.0.0")]
26+
[assembly: AssemblyFileVersion("1.0.0.0")]
27+
28+
// Add some common permissions, these can be removed if not needed
29+
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
30+
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]

0 commit comments

Comments
 (0)