Skip to content

Commit c746fd1

Browse files
committed
WinRT now also New Expression is working
1 parent a40dbc1 commit c746fd1

File tree

6 files changed

+141
-36
lines changed

6 files changed

+141
-36
lines changed

Src/System.Linq.Dynamic.WinRT.Tests/Package.appxmanifest

+23-23
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@
2020
<Resources>
2121
<Resource Language="x-generate"/>
2222
</Resources>
23-
23+
2424
<Applications>
25-
<Application Id="vstest.executionengine.App"
26-
Executable="vstest.executionengine.appcontainer.exe"
25+
<Application Id="vstest.executionengine.App"
26+
Executable="vstest.executionengine.appcontainer.exe"
2727
EntryPoint="vstest.executionengine.App">
28-
<VisualElements
29-
DisplayName="NoUIEntryPoints"
30-
Logo="Images\UnitTestLogo.png"
31-
SmallLogo="Images\UnitTestSmallLogo.png"
32-
Description="vstest.executionengine.App"
33-
ForegroundText="light"
34-
BackgroundColor="#0084FF">
35-
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
36-
</VisualElements>
28+
<VisualElements
29+
DisplayName="NoUIEntryPoints"
30+
Logo="Images\UnitTestLogo.png"
31+
SmallLogo="Images\UnitTestSmallLogo.png"
32+
Description="vstest.executionengine.App"
33+
ForegroundText="light"
34+
BackgroundColor="#0084FF">
35+
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
36+
</VisualElements>
3737
</Application>
3838

39-
<Application Id="vstest.executionengine.x86.App"
40-
Executable="vstest.executionengine.appcontainer.x86.exe"
39+
<Application Id="vstest.executionengine.x86.App"
40+
Executable="vstest.executionengine.appcontainer.x86.exe"
4141
EntryPoint="vstest.executionengine.x86.App">
42-
<VisualElements
43-
DisplayName="NoUIEntryPoints"
44-
Logo="Images\UnitTestLogo.png"
45-
SmallLogo="Images\UnitTestSmallLogo.png"
46-
Description="vstest.executionengine.x86.App"
47-
ForegroundText="light"
48-
BackgroundColor="#0084FF">
49-
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
50-
</VisualElements>
42+
<VisualElements
43+
DisplayName="NoUIEntryPoints"
44+
Logo="Images\UnitTestLogo.png"
45+
SmallLogo="Images\UnitTestSmallLogo.png"
46+
Description="vstest.executionengine.x86.App"
47+
ForegroundText="light"
48+
BackgroundColor="#0084FF">
49+
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
50+
</VisualElements>
5151
</Application>
5252
</Applications>
5353
<Capabilities>

Src/System.Linq.Dynamic.WinRT.Tests/System.Linq.Dynamic.WinRT.Tests.csproj

+6-5
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@
109109
</PropertyGroup>
110110
<ItemGroup>
111111
<!--A reference to the entire .Net Framework and Windows SDK are automatically included-->
112-
<SDKReference Include="MSTestFramework, Version=11.0" />
113-
<SDKReference Include="TestPlatform, Version=11.0" />
112+
<SDKReference Include="MSTestFramework, Version=14.0">
113+
<Name>MSTest for Managed Projects</Name>
114+
</SDKReference>
115+
<SDKReference Include="TestPlatform, Version=14.0">
116+
<Name>Microsoft Visual Studio Test Core</Name>
117+
</SDKReference>
114118
</ItemGroup>
115119
<ItemGroup>
116120
<Compile Include="..\System.Linq.Dynamic.Tests\BasicTests.cs">
@@ -137,9 +141,6 @@
137141
<Compile Include="..\System.Linq.Dynamic.Tests\InternalTests.cs">
138142
<Link>InternalTests.cs</Link>
139143
</Compile>
140-
<Compile Include="..\System.Linq.Dynamic\DynamicLinqTypeProvider.cs">
141-
<Link>DynamicLinqTypeProvider.cs</Link>
142-
</Compile>
143144
<Compile Include="UnitTest1.cs" />
144145
<Compile Include="Properties\AssemblyInfo.cs" />
145146
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Dynamic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
8+
namespace System.Linq.Dynamic
9+
{
10+
/// <summary>
11+
/// Provides a base class for dynamic objects created by using the <see cref="DynamicQueryable.Select(IQueryable,string,object[])"/>
12+
/// method. For internal use only.
13+
/// </summary>
14+
public class DynamicClass : DynamicObject
15+
{
16+
Dictionary<string, object> _properties = new Dictionary<string, object>();
17+
18+
//public DynamicClass(IEnumerable<KeyValuePair<string, object>> propertyValues)
19+
//{
20+
// foreach (var pair in propertyValues)
21+
// {
22+
// _properties.Add(pair.Key, pair.Value);
23+
// }
24+
//}
25+
26+
public DynamicClass(KeyValuePair<string, object> _1)
27+
{
28+
_properties.Add(_1.Key, _1.Value);
29+
}
30+
31+
public DynamicClass(KeyValuePair<string, object> _1, KeyValuePair<string, object> _2)
32+
{
33+
_properties.Add(_1.Key, _1.Value);
34+
_properties.Add(_2.Key, _2.Value);
35+
}
36+
37+
public DynamicClass(KeyValuePair<string, object> _1, KeyValuePair<string, object> _2, KeyValuePair<string, object> _3)
38+
{
39+
_properties.Add(_1.Key, _1.Value);
40+
_properties.Add(_2.Key, _2.Value);
41+
_properties.Add(_3.Key, _3.Value);
42+
}
43+
44+
public DynamicClass(KeyValuePair<string, object> _1, KeyValuePair<string, object> _2, KeyValuePair<string, object> _3, KeyValuePair<string, object> _4)
45+
{
46+
_properties.Add(_1.Key, _1.Value);
47+
_properties.Add(_2.Key, _2.Value);
48+
_properties.Add(_3.Key, _3.Value);
49+
_properties.Add(_4.Key, _4.Value);
50+
}
51+
52+
public object this[string name]
53+
{
54+
get
55+
{
56+
object result;
57+
if (_properties.TryGetValue(name, out result))
58+
return result;
59+
60+
return null;
61+
}
62+
set
63+
{
64+
if (_properties.ContainsKey(name))
65+
_properties[name] = value;
66+
else
67+
_properties.Add(name, value);
68+
}
69+
}
70+
71+
public override IEnumerable<string> GetDynamicMemberNames()
72+
{
73+
return _properties.Keys;
74+
}
75+
76+
public override bool TryGetMember(GetMemberBinder binder, out object result)
77+
{
78+
var name = binder.Name;
79+
_properties.TryGetValue(name, out result);
80+
81+
return true;
82+
}
83+
84+
public override bool TrySetMember(SetMemberBinder binder, object value)
85+
{
86+
var name = binder.Name;
87+
if (_properties.ContainsKey(name))
88+
_properties[name] = value;
89+
else
90+
_properties.Add(name, value);
91+
92+
return true;
93+
}
94+
}
95+
}

Src/System.Linq.Dynamic.WinRT/System.Linq.Dynamic.WinRT.csproj

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@
104104
<Compile Include="..\System.Linq.Dynamic\BasicQueryable.cs">
105105
<Link>BasicQueryable.cs</Link>
106106
</Compile>
107-
<Compile Include="..\System.Linq.Dynamic\DynamicClass.cs">
108-
<Link>DynamicClass.cs</Link>
109-
</Compile>
110107
<Compile Include="..\System.Linq.Dynamic\DynamicExpression.cs">
111108
<Link>DynamicExpression.cs</Link>
112109
</Compile>
@@ -144,6 +141,7 @@
144141
<Link>Res.cs</Link>
145142
</Compile>
146143
<Compile Include="AppDomain.cs" />
144+
<Compile Include="DynamicClass.cs" />
147145
<Compile Include="ExtensionMethods.cs" />
148146
<Compile Include="Properties\AssemblyInfo.cs" />
149147
</ItemGroup>

Src/System.Linq.Dynamic.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.21730.1
4+
VisualStudioVersion = 14.0.21901.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Linq.Dynamic", "System.Linq.Dynamic\System.Linq.Dynamic.csproj", "{B6EDF157-6153-4684-A577-DE33896DBAA8}"
77
EndProject

Src/System.Linq.Dynamic/ExpressionParser.cs

+15-4
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp
953953

954954
Expression ParseNew()
955955
{
956-
#if !NETFX_CORE
957956
NextToken();
958957
ValidateToken(TokenId.OpenParen, Res.OpenParenExpected);
959958
NextToken();
@@ -983,16 +982,28 @@ Expression ParseNew()
983982
}
984983
ValidateToken(TokenId.CloseParen, Res.CloseParenOrCommaExpected);
985984
NextToken();
986-
985+
986+
#if !NETFX_CORE
987987
Type type = DynamicExpression.CreateClass(properties);
988988

989989
MemberBinding[] bindings = new MemberBinding[properties.Count];
990990
for (int i = 0; i < bindings.Length; i++)
991991
bindings[i] = Expression.Bind(type.GetProperty(properties[i].Name), expressions[i]);
992992
return Expression.MemberInit(Expression.New(type), bindings);
993993
#else
994-
return null;
995-
#endif
994+
Type type = typeof(DynamicClass);
995+
List<Expression> paras = new List<Expression>();
996+
var constructorKeyValuePair = typeof(KeyValuePair<string, object>).GetTypeInfo().DeclaredConstructors.First();
997+
for (int i = 0; i < properties.Count; i++)
998+
{
999+
var item = Expression.New(constructorKeyValuePair, new[] { (Expression)Expression.Constant(properties[i].Name), expressions[i] });
1000+
paras.Add(item);
1001+
}
1002+
var constructor = type.GetTypeInfo().DeclaredConstructors.First(x => x.GetParameters().Count() == properties.Count());
1003+
var instance = Expression.New(constructor, paras);
1004+
1005+
return instance;
1006+
#endif
9961007
}
9971008

9981009
Expression ParseLambdaInvocation(LambdaExpression lambda)

0 commit comments

Comments
 (0)