Skip to content

Commit a9458da

Browse files
authored
Merge pull request #23 from ekonbenefits/net-standard
Porting to cross compile to .net standard 2.0
2 parents e349874 + 0444d33 commit a9458da

File tree

18 files changed

+152
-341
lines changed

18 files changed

+152
-341
lines changed

.appveyor.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ configuration: Debug
88
build: off
99

1010
skip_branch_with_pr: true
11+
skip_tags: true
12+
13+
before_deploy:
14+
- ps: $env:VersionPrefix=(Select-Xml -Path ./Version.props -XPath "/Project/PropertyGroup/VersionPrefix").Node.'#text'
1115

1216
environment:
1317
vsuffix: alpha$(APPVEYOR_BUILD_NUMBER)
@@ -24,26 +28,50 @@ test:
2428
except:
2529
- Performance
2630

31+
after_test:
32+
- ps: dotnet test .\Tests\UnitTestImpromptuInterface\UnitTestImpromptuInterface.csproj -f netcoreapp2.0 --no-build --no-restore --filter=TestCategory!=Performance --logger="trx;LogFileName=testresults.trx" --configuration=$env:configuration
33+
34+
on_finish:
35+
- ps: $wc = New-Object 'System.Net.WebClient'
36+
- ps: $wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\Tests\UnitTestImpromptuInterface\TestResults\testresults.trx))
37+
38+
39+
deploy:
40+
- provider: NuGet
41+
server: https://www.myget.org/F/dynamitey-ci/api/v2/package
42+
api_key:
43+
secure: yKbBrG0QiTfXUvND1/cMMNHxH1Bgal5g7c0pWGwqvjCtKGTtWkpvE2KlZb6E2ZgB
44+
skip_symbols: false
45+
symbol_server: https://www.myget.org/F/dynamitey-ci/symbols/api/v2/package
46+
47+
- provider: GitHub
48+
artifact: /.*\.nupkg/ # upload all NuGet packages to release assets
49+
tag: v$(VersionPrefix)$(vsuffix)
50+
description: 'Release description'
51+
auth_token:
52+
secure: JyJYSgeJYFmkaFy7Gro2dQyv/fqZwz1EzJmp2Nf99H6HUpxNR7ilA/OGPcQk0pA8
53+
draft: true
54+
prerelease: $(is_prerelease)
55+
56+
2757
artifacts:
2858
- path: ImpromptuInterface\bin\$(configuration)\*.nupkg
2959
name: ImpromptuInterface
3060

3161
for:
3262
- branches:
3363
except:
34-
- /v.*/
64+
- /deploy-v.*/
3565
- branches:
3666
only:
37-
- /v.*-beta/
67+
- /deploy-v.*-beta.*/
3868
environment:
3969
vsuffix: beta$(APPVEYOR_BUILD_NUMBER)
4070
is_prerelease: true
4171
- branches:
4272
only:
43-
- /v[\d,.]*/
73+
- /deploy-v[\d,.]*/
4474
configuration: Release
4575
environment:
4676
vsuffix: $(APPVEYOR_BUILD_NUMBER)
47-
is_prerelease: false
48-
49-
77+
is_prerelease: false

.ci/RunTests.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh -x
22

33
runTest(){
4-
mono --runtime=v4.0 packages/nunit.runners/2.6.1/tools/nunit-console.exe -noxml -nodots -labels $@
4+
mono --runtime=v4.0 packages/nunit.consolerunner/3.7.0/tools/nunit3-console.exe --noresult -labels=All "$@"
55
if [ $? -ne 0 ]
66
then
77
exit 1
88
fi
99
}
1010

11-
runTest Tests/UnitTestImpromptuInterface/bin/Debug/UnitTestImpromptuInterface.dll -exclude=Performance
12-
runTest Tests/UnitTestImpromptuInterface.Clay/bin/Debug/UnitTestImpromptuInterface.Clay.dll -exclude=Performance
13-
11+
runTest Tests/UnitTestImpromptuInterface/bin/Debug/net462/UnitTestImpromptuInterface.exe --where="cat != Performance"
12+
runTest Tests/UnitTestImpromptuInterface.Clay/bin/Debug/UnitTestImpromptuInterface.Clay.dll --where="cat != Performance"
13+
dotnet test Tests/UnitTestImpromptuInterface/UnitTestImpromptuInterface.csproj -f netcoreapp2.0 --no-build --no-restore --filter="TestCategory!=Performance" --configuration=Debug
1414
exit $?

.nuget/NuGet.Config

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

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ matrix:
88
dist: trusty
99
sudo: required
1010
- os: osx
11+
osx_image: "xcode8.3"
1112

1213
solution: ImpromptuInterface.sln
1314

14-
mono:
15-
- beta
15+
mono: beta
16+
dotnet: 2.0.0
1617

1718
install:
1819
- msbuild /t:restore

ImpromptuInterface/ImpromptuInterface.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net40</TargetFramework>
3+
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
44
<SignAssembly>True</SignAssembly>
55
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
66
<Description>A Lightweight Duck Casting Framework for dynamic C#</Description>
@@ -18,11 +18,15 @@
1818
</PropertyGroup>
1919
<Import Project="..\Version.props" />
2020
<ItemGroup>
21-
<PackageReference Include="Dynamitey" Version="2.0.5-alpha87" />
22-
</ItemGroup>
23-
<ItemGroup>
24-
<Reference Include="Microsoft.CSharp" />
21+
<PackageReference Include="Dynamitey" Version="2.0.6-beta111" />
2522
</ItemGroup>
23+
<ItemGroup Condition="'$(TargetFramework)'=='net40'">
24+
<Reference Include="Microsoft.CSharp" />
25+
</ItemGroup>
26+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
27+
<PackageReference Include="System.Reflection.Emit" Version="4.3.*" />
28+
<PackageReference Include="Microsoft.CSharp" Version="4.4.*" />
29+
</ItemGroup>
2630
<ItemGroup>
2731
<Folder Include="Properties\" />
2832
</ItemGroup>

ImpromptuInterface/src/EmitProxy/BuildProxy.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,27 @@ namespace ImpromptuInterface.Build
2727
using System.Reflection.Emit;
2828
using System.Runtime.CompilerServices;
2929
using Microsoft.CSharp.RuntimeBinder;
30-
30+
31+
32+
33+
#if NET40
34+
internal static class CompatHelper
35+
{
36+
public static Type GetTypeInfo(this Type type) => type;
37+
38+
public static Type CreateTypeInfo(this TypeBuilder builder) => builder.CreateType();
39+
40+
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) => AppDomain.CurrentDomain.DefineDynamicAssembly(name, access);
41+
}
42+
43+
#else
44+
internal static class CompatHelper
45+
{
46+
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) => AssemblyBuilder.DefineDynamicAssembly(name, access);
47+
48+
}
49+
50+
#endif
3151

3252
///<summary>
3353
/// Does most of the work buiding and caching proxies
@@ -58,7 +78,8 @@ public static TInterface RecursiveActLike<TInterface>(object target) where TInte
5878
}
5979

6080

61-
#if !SILVERLIGHT
81+
#if NET40
82+
6283
internal class TempBuilder : IDisposable
6384
{
6485
private readonly string _name;
@@ -104,8 +125,8 @@ public static IDisposable WriteOutDll(string name)
104125

105126
return new TempBuilder(name);
106127
}
107-
108128
#endif
129+
109130

110131

111132
/// <summary>
@@ -240,7 +261,7 @@ private static Type BuildTypeHelper(ModuleBuilder builder, Type contextType, IDi
240261
MakePropertyDescribedProperty(builder, tB, contextType, tInterface.Key, tInterface.Value);
241262

242263
}
243-
var tType = tB.CreateType();
264+
var tType = tB.CreateTypeInfo();
244265
return tType;
245266
}
246267

@@ -375,7 +396,7 @@ private static Type BuildTypeHelper(ModuleBuilder builder,Type contextType,param
375396
MakeEvent(builder, tInfo, tB, contextType, defaultImp: tPropertyNameHash.Add(tInfo.Name));
376397
}
377398
}
378-
var tType = tB.CreateType();
399+
var tType = tB.CreateTypeInfo();
379400
return tType;
380401
}
381402

@@ -563,7 +584,7 @@ private static void MakeMethod(ModuleBuilder builder,MethodInfo info, TypeBuilde
563584

564585

565586

566-
var tCallSite = tCStp.CreateType();
587+
Type tCallSite = tCStp.CreateTypeInfo();
567588

568589
var tPublicPrivate = MethodAttributes.Public;
569590
var tPrefixName = tEmitInfo.Name;
@@ -891,7 +912,7 @@ private static void MakeEvent(ModuleBuilder builder, EventInfo info, TypeBuilder
891912

892913
tEmitInfo.CallSiteInvokeSetFuncType = tCStp.DefineCallsiteField(tEmitInfo.CallSiteInvokeSetName, typeof(object), typeof(object));
893914

894-
tEmitInfo.CallSiteType = tCStp.CreateType();
915+
tEmitInfo.CallSiteType = tCStp.CreateTypeInfo();
895916

896917
var tMp = typeBuilder.DefineEvent(info.Name, EventAttributes.None, tEmitInfo.ResolveReturnType);
897918

@@ -1228,7 +1249,7 @@ private static void MakePropertyHelper(ModuleBuilder builder, TypeBuilder typeBu
12281249
emitInfo.CallSiteInvokeSetFuncType = tCStp.DefineCallsiteField(tInvokeSet, typeof(object), emitInfo.ResolvedParamTypes);
12291250
}
12301251

1231-
emitInfo.CallSiteType = tCStp.CreateType();
1252+
emitInfo.CallSiteType = tCStp.CreateTypeInfo();
12321253

12331254

12341255

@@ -1676,7 +1697,7 @@ private static Type GenerateFullDelegate(TypeBuilder builder, Type returnType,
16761697

16771698

16781699

1679-
return tBuilder.CreateType();
1700+
return tBuilder.CreateTypeInfo();
16801701

16811702
}
16821703

@@ -1711,15 +1732,15 @@ private static void GenerateAssembly(string name, AssemblyBuilderAccess access,
17111732
var tName = new AssemblyName(name);
17121733

17131734
ab =
1714-
AppDomain.CurrentDomain.DefineDynamicAssembly(
1735+
CompatHelper.DefineDynamicAssembly(
17151736
tName,
17161737
access);
17171738

1718-
#if !SILVERLIGHT
1739+
#if NET40
17191740
if (access== AssemblyBuilderAccess.RunAndSave || access == AssemblyBuilderAccess.Save)
17201741
mb = ab.DefineDynamicModule("MainModule", string.Format("{0}.dll", tName.Name));
17211742
else
1722-
#endif
1743+
#endif
17231744
mb = ab.DefineDynamicModule("MainModule");
17241745
}
17251746
}

ImpromptuInterface/src/EmitProxy/EmitExtensions.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -558,17 +558,6 @@ public static void EmitTypeOf(this ILGenerator generator, Type type)
558558
}
559559

560560

561-
/// <summary>
562-
/// Emits the typeof(Type)
563-
/// </summary>
564-
/// <param name="generator">The generator.</param>
565-
/// <param name="type">The type.</param>
566-
public static void EmitTypeOf(this ILGenerator generator, TypeToken type)
567-
{
568-
569-
generator.Emit(OpCodes.Ldtoken, type.Token);
570-
var tTypeMeth = typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) });
571-
generator.Emit(OpCodes.Call, tTypeMeth);
572-
}
561+
573562
}
574563
}

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.net 4.0 framework to allow you to wrap any object (static or dynamic) with a static interface even though it didn't inherit from it. It does this by emitting cached dynamic binding code inside a proxy.
1+
net4.0/netstd2.0 framework to allow you to wrap any object (static or dynamic) with a static interface even though it didn't inherit from it. It does this by emitting cached dynamic binding code inside a proxy.
22

33
ImpromptuInterface is available Nuget [![NuGet](https://img.shields.io/nuget/dt/ImpromptuInterface.svg)](https://www.nuget.org/packages/ImpromptuInterface/)
44

Tests/UnitTestImpromptuInterface.Clay/UnitTestImpromptuInterface.Clay.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,10 +10,11 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>UnitTestImpromptuInterface.Clay</RootNamespace>
1212
<AssemblyName>UnitTestImpromptuInterface.Clay</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\impromptuinterface\</SolutionDir>
1616
<RestorePackages>true</RestorePackages>
17+
<TargetFrameworkProfile />
1718
</PropertyGroup>
1819
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1920
<DebugSymbols>true</DebugSymbols>
@@ -23,6 +24,7 @@
2324
<DefineConstants>DEBUG;TRACE</DefineConstants>
2425
<ErrorReport>prompt</ErrorReport>
2526
<WarningLevel>4</WarningLevel>
27+
<Prefer32Bit>false</Prefer32Bit>
2628
</PropertyGroup>
2729
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2830
<DebugType>pdbonly</DebugType>
@@ -31,13 +33,14 @@
3133
<DefineConstants>TRACE</DefineConstants>
3234
<ErrorReport>prompt</ErrorReport>
3335
<WarningLevel>4</WarningLevel>
36+
<Prefer32Bit>false</Prefer32Bit>
3437
</PropertyGroup>
3538
<ItemGroup>
3639
<PackageReference Include="Castle.Core" Version="1.1.*" />
3740
<PackageReference Include="Castle.DynamicProxy" Version="2.1.*" />
3841
<PackageReference Include="IronPython" Version="2.7.*" />
3942
<PackageReference Include="log4net" Version="1.2.10" />
40-
<PackageReference Include="NUnit" Version="2.6.1" />
43+
<PackageReference Include="NUnit" Version="3.7.1" />
4144
<PackageReference Include="Clay" Version="1.0" />
4245
</ItemGroup>
4346
<ItemGroup>

Tests/UnitTestImpromptuInterface/Com.cs

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

0 commit comments

Comments
 (0)