diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..c740c0d --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,45 @@ +image: Visual Studio 2017 + +configuration: Debug + +build: off + +build_script: + - cmd: set PATH=%PATH%;C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\ + - cmd: fsi --exec ./build.fsx + +test: off + +artifacts: + - path: '**\bin\*\*.nupkg' + +skip_branch_with_pr: true + +deploy: + - provider: NuGet + server: https://www.myget.org/F/dynamitey-ci/api/v2/package + api_key: + secure: yKbBrG0QiTfXUvND1/cMMNHxH1Bgal5g7c0pWGwqvjCtKGTtWkpvE2KlZb6E2ZgB + skip_symbols: false + symbol_server: https://www.myget.org/F/dynamitey-ci/symbols/api/v2/package + +for: + - branches: + except: + - /v.*/ + environment: + vsuffix: alpha$(APPVEYOR_BUILD_NUMBER) + is_prerelease: true + - branches: + only: + - /v.*-beta/ + environment: + vsuffix: beta$(APPVEYOR_BUILD_NUMBER) + is_prerelease: true + - branches: + only: + - /v[\d,.]*/ + configuration: Release + environment: + vsuffix: $(APPVEYOR_BUILD_NUMBER) + is_prerelease: false \ No newline at end of file diff --git a/.ci/codebetterci.proj b/.ci/codebetterci.proj deleted file mode 100644 index 8e26ada..0000000 --- a/.ci/codebetterci.proj +++ /dev/null @@ -1,17 +0,0 @@ - - - - Dynamitey - - - - Configuration=Release;UseOldPcl=true; - - - Configuration=Release;OutputPath=bin\Release.net40\;IntermediateOutputPath=obj\Release.net40\;UseNet40=true; - - - - - - \ No newline at end of file diff --git a/.ci/nunit.sh b/.ci/nunit.sh deleted file mode 100755 index 44e428c..0000000 --- a/.ci/nunit.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -x - -mono --runtime=v4.0 .nuget/NuGet.exe install NUnit.Runners -Version 2.6.1 -o packages - -runTest(){ - mono --runtime=v4.0 packages/NUnit.Runners.2.6.1/tools/nunit-console.exe -noxml -nodots -labels -stoponerror $@ - if [ $? -ne 0 ] - then - exit 1 - fi -} - -runTest $1 -exclude=Performance - -exit $? \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5805f4c..761345c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,150 +1,158 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -f -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -# ========================= -# Windows detritus -# ========================= - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap -.DS_Store - -/dist/*.nupkg +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +f +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + +/dist/*.nupkg + +*.userprefs + +.fake/* +.nuget/NuGet.exe + +.idea/* +.vs/* diff --git a/.nuget/Microsoft.Build.dll b/.nuget/Microsoft.Build.dll deleted file mode 100644 index 43728a4..0000000 Binary files a/.nuget/Microsoft.Build.dll and /dev/null differ diff --git a/.nuget/Microsoft.Build.readme b/.nuget/Microsoft.Build.readme deleted file mode 100644 index 6bd0a5b..0000000 --- a/.nuget/Microsoft.Build.readme +++ /dev/null @@ -1 +0,0 @@ -This Microsoft.Build.dll comes v3.X of the Mono Project. Mit licensed Copyright (C) 2012 Xamarin Inc. diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config deleted file mode 100644 index 67f8ea0..0000000 --- a/.nuget/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe deleted file mode 100644 index cb3ed03..0000000 Binary files a/.nuget/NuGet.exe and /dev/null differ diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets deleted file mode 100644 index 90dee61..0000000 --- a/.nuget/NuGet.targets +++ /dev/null @@ -1,135 +0,0 @@ - - - - $(MSBuildProjectDirectory)\..\ - - - false - - - false - - - true - - - false - - - - - - - - - - - $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) - $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) - - - - - $(SolutionDir).nuget - packages.config - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 $(NuGetExePath) - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - - $(SolutionDir) - $(SolutionDir) - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDirParsed)" - $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4d70afb..6e2d71c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,26 @@ # Travis-CI Build for dynamitey # see travis-ci.org for details -language: objective-c +language: csharp +matrix: + include: + - os: linux + dist: trusty + sudo: required + - os: osx + osx_image: "xcode8.3" + +solution: Dynamitey.sln + +mono: latest +dotnet: 2.0.0 + +install: + - msbuild /ver -env: - global: - - EnableNuGetPackageRestore=true - matrix: - - MONO_VER="3.2.4" -before_install: - # Make sure mono is installed, - - wget "http://download.mono-project.com/archive/${MONO_VER}/macos-10-x86/MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.pkg" - - sudo installer -pkg "MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.pkg" -target / script: - - xbuild - - .ci/nunit.sh Tests/bin/Debug/Tests.dll + - ./build.fsx + +branches: + only: + - master \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c71ce74 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "./build.fsx", + "args": ["Test"], + "windows":{ + "command": "C:\\Program Files (x86)\\Microsoft SDKs\\F#\\4.1\\Framework\\v4.0\\fsi", + "args": ["--exec", "./build.fsx", "Test"] + }, + "isShellCommand": true, + "showOutput": "always", + "problemMatcher":"$msCompile" +} \ No newline at end of file diff --git a/Dynamitey.sln b/Dynamitey.sln index b5425b2..d54a794 100644 --- a/Dynamitey.sln +++ b/Dynamitey.sln @@ -1,20 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dynamitey", "Dynamitey\Dynamitey.csproj", "{CE699AB8-4122-4369-BAA6-76244A0734E4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{CB47488D-6ECE-4697-90C2-3BDA8488F00C}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection -EndProject +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.9 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{691EBA79-CAA4-4670-BC8B-4537F990ADBF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{C33F07DB-7ACB-4081-92C2-BB739CB605C0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SupportLibrary1", "SupportLibrary1\SupportLibrary1.csproj", "{348152A9-6A9C-4115-B60A-9E08CA72451D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SupportLibrary", "SupportLibrary\SupportLibrary.csproj", "{18E19833-D47E-4A7F-AE64-31E28FEF8728}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dynamitey", "Dynamitey\Dynamitey.csproj", "{8902AFBA-4ACA-4880-B606-ADEC6BB21A1B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,24 +17,24 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CE699AB8-4122-4369-BAA6-76244A0734E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CE699AB8-4122-4369-BAA6-76244A0734E4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CE699AB8-4122-4369-BAA6-76244A0734E4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CE699AB8-4122-4369-BAA6-76244A0734E4}.Release|Any CPU.Build.0 = Release|Any CPU {C33F07DB-7ACB-4081-92C2-BB739CB605C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C33F07DB-7ACB-4081-92C2-BB739CB605C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {C33F07DB-7ACB-4081-92C2-BB739CB605C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {C33F07DB-7ACB-4081-92C2-BB739CB605C0}.Release|Any CPU.Build.0 = Release|Any CPU - {348152A9-6A9C-4115-B60A-9E08CA72451D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {348152A9-6A9C-4115-B60A-9E08CA72451D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {348152A9-6A9C-4115-B60A-9E08CA72451D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {348152A9-6A9C-4115-B60A-9E08CA72451D}.Release|Any CPU.Build.0 = Release|Any CPU + {18E19833-D47E-4A7F-AE64-31E28FEF8728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18E19833-D47E-4A7F-AE64-31E28FEF8728}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18E19833-D47E-4A7F-AE64-31E28FEF8728}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18E19833-D47E-4A7F-AE64-31E28FEF8728}.Release|Any CPU.Build.0 = Release|Any CPU + {8902AFBA-4ACA-4880-B606-ADEC6BB21A1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8902AFBA-4ACA-4880-B606-ADEC6BB21A1B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8902AFBA-4ACA-4880-B606-ADEC6BB21A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8902AFBA-4ACA-4880-B606-ADEC6BB21A1B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {C33F07DB-7ACB-4081-92C2-BB739CB605C0} = {691EBA79-CAA4-4670-BC8B-4537F990ADBF} - {348152A9-6A9C-4115-B60A-9E08CA72451D} = {691EBA79-CAA4-4670-BC8B-4537F990ADBF} + {18E19833-D47E-4A7F-AE64-31E28FEF8728} = {691EBA79-CAA4-4670-BC8B-4537F990ADBF} EndGlobalSection EndGlobal diff --git a/Dynamitey/Builder.cs b/Dynamitey/Builder.cs index f59f92b..515228d 100644 --- a/Dynamitey/Builder.cs +++ b/Dynamitey/Builder.cs @@ -29,7 +29,7 @@ public static class Builder /// New Builder /// /// - public static IImpromptuBuilder New() + public static IBuilder New() { return new Builder(); } @@ -41,7 +41,7 @@ public static IImpromptuBuilder New() /// /// The type of the object prototype. /// - public static IImpromptuBuilder New() where TObjectPrototype : new() + public static IBuilder New() where TObjectPrototype : new() { return new Builder(); } diff --git a/Dynamitey/CacheableInvocation.cs b/Dynamitey/CacheableInvocation.cs index 806727a..dd124fa 100644 --- a/Dynamitey/CacheableInvocation.cs +++ b/Dynamitey/CacheableInvocation.cs @@ -4,6 +4,8 @@ using System.Runtime.CompilerServices; using Dynamitey.Internal.Optimization; using Microsoft.CSharp.RuntimeBinder; +using System.Reflection; +using Dynamitey.Internal.Compat; namespace Dynamitey { @@ -261,7 +263,7 @@ public override object Invoke(object target, params object[] args) { case InvocationKind.Constructor: var tTarget = (Type) target; - return InvokeHelper.InvokeConstructorCallSite(tTarget, tTarget.IsValueType, args, _argNames, + return InvokeHelper.InvokeConstructorCallSite(tTarget, tTarget.GetTypeInfo().IsValueType, args, _argNames, ref _callSite); case InvocationKind.Convert: return InvokeHelper.InvokeConvertCallSite(target, _convertExplicit, _convertType, _context, diff --git a/Dynamitey/Dynamic.cs b/Dynamitey/Dynamic.cs index 6c9601a..b607ebd 100644 --- a/Dynamitey/Dynamic.cs +++ b/Dynamitey/Dynamic.cs @@ -15,29 +15,37 @@ using System.Collections.Generic; using System.Dynamic; +using System.Globalization; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Runtime.CompilerServices; -using System.Threading; using Dynamitey.Internal; using Dynamitey.Internal.Optimization; using Microsoft.CSharp.RuntimeBinder; using System.Text.RegularExpressions; +using Dynamitey.Internal.Compat; namespace Dynamitey { using System; - + /// /// Main API /// public static class Dynamic { - + /// + /// Clears the dynamic binding caches. + /// + public static void ClearCaches() + { + InvokeHelper.ClearAllCaches(); + } private static readonly Type ComObjectType; @@ -47,7 +55,7 @@ static Dynamic() { try { - ComObjectType = typeof(object).Assembly.GetType("System.__ComObject"); + ComObjectType = typeof(object).GetTypeInfo().Assembly.GetType("System.__ComObject"); ComBinder = new DynamicObjects.LateType( "System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); } @@ -130,7 +138,7 @@ public static CallSite CreateCallSite(CallSiteBinder binder, String_OR_Inv /// public static dynamic Linq(object enumerable) { - if(enumerable.GetType().GetInterfaces().Where(it=>it.IsGenericType) + if(enumerable.GetType().GetTypeInfo().GetInterfaces().Where(it=>it.GetTypeInfo().IsGenericType) .All(it => it.GetGenericTypeDefinition() != typeof(IEnumerable<>))) { var tEnum = enumerable as System.Collections.IEnumerable; @@ -253,6 +261,10 @@ public static dynamic InvokeBinaryOperator(dynamic leftArg, ExpressionType op, d return leftArg | rightArg; case ExpressionType.And: return leftArg & rightArg; + case ExpressionType.OrElse: + return leftArg || rightArg; + case ExpressionType.AndAlso: + return leftArg && rightArg; default: throw new ArgumentException("Unsupported Operator", "op"); } @@ -529,7 +541,7 @@ public static dynamic Curry(object target, int? totalArgCount = null) /// public static dynamic Curry(Delegate target) { - return new Curry(target, target.Method.GetParameters().Length); + return new Curry(target, target.GetMethodInfo().GetParameters().Length); } @@ -693,11 +705,12 @@ public static dynamic InvokeConvert(object target, Type type, bool @explicit =fa /// public static dynamic CoerceToDelegate(object invokeableObject, Type delegateType) { - if (!typeof(Delegate).IsAssignableFrom(delegateType.BaseType)) + var delegateTypeInfo = delegateType.GetTypeInfo(); + if (!typeof(Delegate).GetTypeInfo().IsAssignableFrom(delegateTypeInfo.BaseType)) { return null; } - var tDelMethodInfo = delegateType.GetMethod("Invoke"); + var tDelMethodInfo = delegateTypeInfo.GetMethod("Invoke"); var tReturnType = tDelMethodInfo.ReturnType; var tAction = tReturnType == typeof(void); var tParams = tDelMethodInfo.GetParameters(); @@ -707,7 +720,7 @@ public static dynamic CoerceToDelegate(object invokeableObject, Type delegateTyp : InvokeHelper.WrapFunc(tReturnType, invokeableObject, tLength); - if (!InvokeHelper.IsActionOrFunc(delegateType) || tParams.Any(it => it.ParameterType.IsValueType)) + if (!InvokeHelper.IsActionOrFunc(delegateType) || tParams.Any(it => it.ParameterType.GetTypeInfo().IsValueType)) //Conditions that aren't contravariant; { Delegate tGetResult; @@ -800,7 +813,8 @@ internal static readonly Type TypeConverterAttributeSL /// public static dynamic CoerceConvert(object target, Type type) { - if (target != null && !type.IsInstanceOfType(target) && !IsDBNull(target)) + var typeInfo = type.GetTypeInfo(); + if (target != null && !typeInfo.IsInstanceOfType(target) && !IsDBNull(target)) { var delegateConversion = CoerceToDelegate(target, type); @@ -809,7 +823,7 @@ public static dynamic CoerceConvert(object target, Type type) return delegateConversion; - if (type.IsInterface && Impromptu.IsAvailable) + if (typeInfo.IsInterface && Impromptu.IsAvailable) { @@ -841,20 +855,20 @@ public static dynamic CoerceConvert(object target, Type type) catch (RuntimeBinderException) { Type tReducedType = type; - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) + if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) { - tReducedType = type.GetGenericArguments().First(); + tReducedType = typeInfo.GetGenericArguments().First(); } - if (typeof (Enum).IsAssignableFrom(tReducedType) && target is string) + if (typeof (Enum).GetTypeInfo().IsAssignableFrom(tReducedType) && target is string) { target = Enum.Parse(tReducedType, target as String, true); } - else if (target is IConvertible && typeof (IConvertible).IsAssignableFrom(tReducedType)) + else if (target is IConvertible && typeof (IConvertible).GetTypeInfo().IsAssignableFrom(tReducedType)) { - target = Convert.ChangeType(target, tReducedType, Thread.CurrentThread.CurrentCulture); + target = Convert.ChangeType(target, tReducedType, Net40.GetDefaultThreadCurrentCulture()); } else @@ -869,7 +883,7 @@ public static dynamic CoerceConvert(object target, Type type) else if (TypeConverterAttributeSL != null) { var tAttributes = - tReducedType.GetCustomAttributes(TypeConverterAttributeSL, false); + tReducedType.GetTypeInfo().GetCustomAttributes(TypeConverterAttributeSL, false); dynamic attribute = tAttributes.FirstOrDefault(); if (attribute != null) { @@ -893,11 +907,11 @@ public static dynamic CoerceConvert(object target, Type type) } } } - else if (((target == null) || IsDBNull(target )) && type.IsValueType) + else if (((target == null) || IsDBNull(target )) && typeInfo.IsValueType) { target = Dynamic.InvokeConstructor(type); } - else if (!type.IsInstanceOfType(target) && IsDBNull(target)) + else if (!typeInfo.IsInstanceOfType(target) && IsDBNull(target)) { return null; } @@ -913,7 +927,7 @@ public static dynamic CoerceConvert(object target, Type type) public static dynamic InvokeConstructor(Type type, params object[] args) { string[] tArgNames; - bool tValue = type.IsValueType; + bool tValue = type.GetTypeInfo().IsValueType; if (tValue && args.Length == 0) //dynamic invocation doesn't see constructors of value types { return Activator.CreateInstance(type); @@ -935,7 +949,7 @@ public static dynamic InvokeConstructor(Type type, params object[] args) /// public static object FastDynamicInvoke(this Delegate del, params object[] args) { - if(del.Method.ReturnType == typeof(void)){ + if(del.GetMethodInfo().ReturnType == typeof(void)){ InvokeHelper.FastDynamicInvokeAction(del, args); return null; @@ -974,7 +988,7 @@ public static IEnumerable GetMemberNames(object target, bool dynamicOnly var tList = new List(); if (!dynamicOnly) { - tList.AddRange(target.GetType().GetProperties().Select(it => it.Name)); + tList.AddRange(target.GetType().GetTypeInfo().GetProperties().Select(it => it.Name)); } var tTarget = target as IDynamicMetaObjectProvider; @@ -984,7 +998,7 @@ public static IEnumerable GetMemberNames(object target, bool dynamicOnly }else { - if (ComObjectType != null && ComObjectType.IsInstanceOfType(target) && ComBinder.IsAvailable) + if (ComObjectType != null && ComObjectType.GetTypeInfo().IsInstanceOfType(target) && ComBinder.IsAvailable) { tList.AddRange(ComBinder.GetDynamicDataMemberNames(target)); } diff --git a/Dynamitey/DynamicObjects/BaseDictionary.cs b/Dynamitey/DynamicObjects/BaseDictionary.cs index 2b8cc1c..1615d86 100644 --- a/Dynamitey/DynamicObjects/BaseDictionary.cs +++ b/Dynamitey/DynamicObjects/BaseDictionary.cs @@ -19,7 +19,6 @@ using System.Dynamic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; using System.Threading; using Dynamitey.Internal.Optimization; using Microsoft.CSharp.RuntimeBinder; diff --git a/Dynamitey/DynamicObjects/BaseForwarder.cs b/Dynamitey/DynamicObjects/BaseForwarder.cs index 30f7194..eacabbd 100644 --- a/Dynamitey/DynamicObjects/BaseForwarder.cs +++ b/Dynamitey/DynamicObjects/BaseForwarder.cs @@ -18,7 +18,6 @@ using System.Dynamic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; using System.Text; using Dynamitey.Internal.Optimization; using Microsoft.CSharp; @@ -239,9 +238,53 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o object[] tArgs = Util.NameArgsIfNecessary(binder.CallInfo, args); + + Type[] types = null; + + try + { + //.net core + // Try and pull generic arguments from binder + IList typeList = Dynamic.InvokeGet(binder, + "TypeArguments"); + if (typeList != null) + { + types = typeList.ToArray(); + } + + } + catch (RuntimeBinderException) + { + types = null; + } + + if (types == null) + { + try + { + //.net 4.0 + // Try and pull generic arguments from binder + IList typeList = Dynamic.InvokeGet(binder, + "Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder.TypeArguments"); + if (typeList != null) + { + + types = typeList.ToArray(); + + } + + } + catch (RuntimeBinderException) + { + types = null; + } + } + + var name = InvokeMemberName.Create; + var fullName = name(binder.Name, types); try { - result = Dynamic.InvokeMember(CallTarget, binder.Name, tArgs); + result = Dynamic.InvokeMember(CallTarget, fullName, tArgs); } catch (RuntimeBinderException) @@ -249,7 +292,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o result = null; try { - Dynamic.InvokeMemberAction(CallTarget, binder.Name, tArgs); + Dynamic.InvokeMemberAction(CallTarget, fullName, tArgs); } catch (RuntimeBinderException) { diff --git a/Dynamitey/DynamicObjects/BaseObject.cs b/Dynamitey/DynamicObjects/BaseObject.cs index 38ed0bf..3babf47 100644 --- a/Dynamitey/DynamicObjects/BaseObject.cs +++ b/Dynamitey/DynamicObjects/BaseObject.cs @@ -18,9 +18,9 @@ using System.ComponentModel; using System.Dynamic; using System.Linq; -using System.Runtime.Serialization; - using System.Reflection; +using Dynamitey.Internal.Compat; + namespace Dynamitey.DynamicObjects { @@ -37,13 +37,15 @@ public interface IEquivalentType /// FauxType EquivalentType { get; set; } } + + /// /// Dynamic Object that knows about the Impromtu Interface return types; /// Override Typical Dynamic Object methods, and use TypeForName to get the return type of an interface member. /// - public abstract class BaseObject : DynamicObject, IEquivalentType, IServiceProvider + public abstract class BaseObject : DynamicObject, IEquivalentType { /// @@ -73,16 +75,26 @@ public bool TryTypeForName(string binderName, out Type type) .Where(it => it is PropertyInfo || it is MethodInfo || it is EventInfo) .Select(it => { - var prop =it as PropertyInfo; - if (prop != null) - return prop.PropertyType; - var mem = it as MethodInfo; - if (mem != null) - return mem.ReturnType; - var eve = it as EventInfo; - if (eve != null) - return eve.EventHandlerType; - return typeof (object); + + switch (it) + { + case PropertyInfo p: + return p.PropertyType; + case MethodInfo m: + return m.ReturnType; + case EventInfo e: + return e.EventHandlerType; +#if NET40 || PROFILE158 + case Type t: + return t; +#else + case TypeInfo t: + return t.UnderlyingSystemType; +#endif + default: + return typeof (object); + } + }).ToList(); ; @@ -90,7 +102,7 @@ public bool TryTypeForName(string binderName, out Type type) return false; foreach (var currenttype in types) { - if (type == null || type == currenttype) + if (type == null || type.Name == currenttype.Name) type = currenttype; else type = typeof (object); @@ -100,23 +112,5 @@ public bool TryTypeForName(string binderName, out Type type) FauxType IEquivalentType.EquivalentType { get; set; } - - object IServiceProvider.GetService(Type serviceType) - { - var aggreTypes =AggreType.MakeTypeAppendable(this); - - if (!aggreTypes.ContainsType(serviceType)) - { - aggreTypes.AddType(serviceType); - - if (serviceType.IsInterface && Dynamic.Impromptu.IsAvailable) - { - return Dynamic.Impromptu.DynamicActLike(this, aggreTypes.GetInterfaceTypes()); - } - - } - - return this; - } } } diff --git a/Dynamitey/DynamicObjects/Builder.cs b/Dynamitey/DynamicObjects/Builder.cs index 10ed42d..a2e6db0 100644 --- a/Dynamitey/DynamicObjects/Builder.cs +++ b/Dynamitey/DynamicObjects/Builder.cs @@ -17,10 +17,10 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Runtime.Serialization; using System.Text; using System.Reflection; using Dynamitey.Internal.Optimization; +using Dynamitey.Internal.Compat; namespace Dynamitey.DynamicObjects { @@ -28,7 +28,7 @@ namespace Dynamitey.DynamicObjects /// /// Interface for simplistic builder options /// - public interface IImpromptuBuilder + public interface IBuilder { /// @@ -121,7 +121,7 @@ public interface IImpromptuBuilder /// /// The type of the object proto type. - public class Builder: BaseObject, IImpromptuBuilder + public class Builder: BaseObject, IBuilder { /// /// Build factory storage @@ -134,8 +134,8 @@ public class Builder: BaseObject, IImpromptuBuilder /// public Builder(){ _buildType = new Dictionary(); - Setup = new SetupTrampoline(this); - Object = new BuilderTrampoline(this); + Setup = new SetupTrampoline(this); + Object = new BuilderTrampoline(this); } /// @@ -260,7 +260,7 @@ public dynamic Array(params dynamic[] contents) /// Creates a Prototype object. /// /// The object. - public dynamic Object { get; private set; } + public dynamic Object { get; } /// /// Sets up object builder @@ -292,7 +292,7 @@ public dynamic ObjectSetup(Func constructorArgsFactory) /// /// Trampoline for builder /// - public class BuilderTrampoline:DynamicObject + public class BuilderTrampoline : DynamicObject { Builder _buider; @@ -326,7 +326,7 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re /// /// Trampoline for setup builder /// - public class SetupTrampoline : DynamicObject + public class SetupTrampoline : DynamicObject { Builder _buider; @@ -411,7 +411,8 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o result = InvokeHelper(binder.CallInfo, args,tBuildType); if (TryTypeForName(binder.Name, out tType)) { - if (tType.IsInterface && result != null && !tType.IsAssignableFrom(result.GetType())) + var typeInfo = tType.GetTypeInfo(); + if (typeInfo.IsInterface && result != null && !typeInfo.IsAssignableFrom(result.GetType())) { // result = Impromptu.DynamicActLike(result, tType); } diff --git a/Dynamitey/DynamicObjects/Dictionary.cs b/Dynamitey/DynamicObjects/Dictionary.cs index 5978be0..2a3597f 100644 --- a/Dynamitey/DynamicObjects/Dictionary.cs +++ b/Dynamitey/DynamicObjects/Dictionary.cs @@ -20,7 +20,6 @@ using System.Dynamic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; namespace Dynamitey.DynamicObjects diff --git a/Dynamitey/DynamicObjects/Dummy.cs b/Dynamitey/DynamicObjects/Dummy.cs index 96c2cbb..ee68efd 100644 --- a/Dynamitey/DynamicObjects/Dummy.cs +++ b/Dynamitey/DynamicObjects/Dummy.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; using System.Text; using Dynamitey.Internal.Optimization; diff --git a/Dynamitey/DynamicObjects/ExtensionToInstanceProxy.cs b/Dynamitey/DynamicObjects/ExtensionToInstanceProxy.cs index 23afa59..4da0d46 100644 --- a/Dynamitey/DynamicObjects/ExtensionToInstanceProxy.cs +++ b/Dynamitey/DynamicObjects/ExtensionToInstanceProxy.cs @@ -4,9 +4,11 @@ using System.Dynamic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; + using System.Text; using Microsoft.CSharp.RuntimeBinder; +using Dynamitey.Internal.Compat; +using Dynamitey.Internal.Optimization; namespace Dynamitey.DynamicObjects { @@ -54,7 +56,7 @@ public ExtensionToInstanceProxy(dynamic target, Type extendedType, Type[] stati if(target is ExtensionToInstanceProxy) throw new ArgumentException("Don't Nest ExtensionToInstance Objects"); - if (IsExtendedType(target)) + if (IsExtendedType(target) || IsExtendedType(Util.GetTargetContext(target,out Type _, out bool _))) { return; } @@ -63,6 +65,10 @@ public ExtensionToInstanceProxy(dynamic target, Type extendedType, Type[] stati } + private object UnwrappedTarget(){ + return Util.GetTargetContext(CallTarget, out Type _, out bool _); + } + /// /// Provides the implementation for operations that get member values. Classes derived from the class can override this method to specify dynamic behavior for operations such as getting a value for a property. /// @@ -77,9 +83,10 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) if (!base.TryGetMember(binder, out result)) { - var tInterface = CallTarget.GetType().GetInterfaces().Single(it => it.Name == _extendedType.Name); + var tInterface = UnwrappedTarget().GetType().GetTypeInfo().GetInterfaces().Single(it => it.Name == _extendedType.Name); + var typeInfo = tInterface.GetTypeInfo(); result = new Invoker(binder.Name, - tInterface.IsGenericType ? tInterface.GetGenericArguments() : new Type[] {},null, this); + typeInfo.IsGenericType ? typeInfo.GetGenericArguments() : new Type[] {},null, this); } return true; } @@ -125,12 +132,12 @@ internal Invoker(string name, Type[] genericParameters, Type[] genericMethodPara { var tNewType = tGenInterface; - if (tNewType.IsGenericType) + if (tNewType.GetTypeInfo().IsGenericType) { tNewType = tNewType.MakeGenericType(GenericParams); } - var members = tNewType.GetMethods(BindingFlags.Instance | + var members = tNewType.GetTypeInfo().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where( it => it.Name == Name).ToList(); foreach (var tMethodInfo in members) @@ -165,16 +172,17 @@ internal Invoker(string name, Type[] genericParameters, Type[] genericMethodPara private Type ReplaceGenericTypes(Type type) { - if (type.IsGenericType && type.ContainsGenericParameters) + var typeInfo = type.GetTypeInfo(); + if (typeInfo.IsGenericType && typeInfo.ContainsGenericParameters) { - var tArgs = type.GetGenericArguments(); + var tArgs = typeInfo.GetGenericArguments(); tArgs = tArgs.Select(ReplaceGenericTypes).ToArray(); return type.GetGenericTypeDefinition().MakeGenericType(tArgs); } - if (type.ContainsGenericParameters) + if (typeInfo.ContainsGenericParameters) { return typeof (object); } @@ -309,7 +317,7 @@ protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] ar var staticType = InvokeContext.CreateStatic; var nameArgs = InvokeMemberName.Create; - var tList = new List { CallTarget }; + var tList = new List { UnwrappedTarget() }; tList.AddRange(args); object result =null; @@ -319,8 +327,8 @@ protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] ar var tGenericPossibles = new List(); if (name.GenericArgs != null && name.GenericArgs.Length > 0) { - var tInterface = CallTarget.GetType().GetInterfaces().Single(it => it.Name == _extendedType.Name); - var tTypeGenerics = (tInterface.IsGenericType ? tInterface.GetGenericArguments() + var tInterface = UnwrappedTarget().GetType().GetTypeInfo().GetInterfaces().Single(it => it.Name == _extendedType.Name); + var tTypeGenerics = (tInterface.GetTypeInfo().IsGenericType ? tInterface.GetTypeInfo().GetGenericArguments() : new Type[] { }).Concat(name.GenericArgs).ToArray(); tGenericPossibles.Add(tTypeGenerics); @@ -348,6 +356,9 @@ protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] ar exceptionList.Add(ex); } } + if(sucess){ + break; + } } if (!sucess) @@ -359,17 +370,18 @@ protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] ar Type tOutType; if (TryTypeForName(name.Name, out tOutType)) { - if (tOutType.IsInterface) + var outTypeInfo = tOutType.GetTypeInfo(); + if (outTypeInfo.IsInterface) { - var tIsGeneric = tOutType.IsGenericType; - if (tOutType.IsGenericType) + var tIsGeneric = outTypeInfo.IsGenericType; + if (outTypeInfo.IsGenericType) { tOutType = tOutType.GetGenericTypeDefinition(); } - if (InstanceHints.Select(it => tIsGeneric && it.IsGenericType ? it.GetGenericTypeDefinition() : it) - .Contains(tOutType)) - { + if (InstanceHints.Select(it => tIsGeneric && it.GetTypeInfo().IsGenericType ? it.GetGenericTypeDefinition() : it) + .Any(it=> it.Name == tOutType.Name)) + { result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints); } } @@ -406,10 +418,10 @@ private bool IsExtendedType(object target) return false; } - bool genericDef = _extendedType.IsGenericTypeDefinition; + bool genericDef = _extendedType.GetTypeInfo().IsGenericTypeDefinition; - return target.GetType().GetInterfaces().Any( - it => ((genericDef && it.IsGenericType) ? it.GetGenericTypeDefinition() : it) == _extendedType); + return target.GetType().GetTypeInfo().GetInterfaces().Any( + it => ((genericDef && it.GetTypeInfo().IsGenericType) ? it.GetGenericTypeDefinition() : it).Name == _extendedType.Name); } diff --git a/Dynamitey/DynamicObjects/Factory.cs b/Dynamitey/DynamicObjects/Factory.cs index 9233d54..5834d12 100644 --- a/Dynamitey/DynamicObjects/Factory.cs +++ b/Dynamitey/DynamicObjects/Factory.cs @@ -15,7 +15,7 @@ using System; using System.Collections.Generic; -using System.Runtime.Serialization; + namespace Dynamitey.DynamicObjects { diff --git a/Dynamitey/DynamicObjects/FauxType.cs b/Dynamitey/DynamicObjects/FauxType.cs index 21a3562..7102219 100644 --- a/Dynamitey/DynamicObjects/FauxType.cs +++ b/Dynamitey/DynamicObjects/FauxType.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; -using System.Text; using System.Reflection; +using Dynamitey.Internal.Compat; + namespace Dynamitey.DynamicObjects { @@ -52,6 +52,33 @@ public virtual bool ContainsType(Type type) } + + public class PropretySpecType : FauxType + { + public IDictionary PropertySpec { get; } + + public PropretySpecType(IDictionary propertySpec) + { + PropertySpec = propertySpec; + } + + public override IEnumerable GetMember(string binderName) + { + if (PropertySpec.TryGetValue(binderName, out var val)) + { + return new[] {val.GetTypeInfo()}; + + } + return Enumerable.Empty(); + } + + public override Type[] GetContainedTypes() + { + return new Type []{}; + } + } + + /// /// A Fake Type that represents a real type /// @@ -99,7 +126,7 @@ public RealType(Type type) /// public override IEnumerable GetMember(string binderName) { - return TargetType.GetMember(binderName); + return TargetType.GetTypeInfo().GetMember(binderName); } /// @@ -158,7 +185,7 @@ public AggreType(params FauxType[] types) /// public Type[] GetInterfaceTypes() { - return Types.SelectMany(it => it.GetContainedTypes()).Where(it => it.IsInterface).ToArray(); + return Types.SelectMany(it => it.GetContainedTypes()).Where(it => it.GetTypeInfo().IsInterface).ToArray(); } /// diff --git a/Dynamitey/DynamicObjects/FluentStringLookup.cs b/Dynamitey/DynamicObjects/FluentStringLookup.cs index 60c2eb9..4673825 100644 --- a/Dynamitey/DynamicObjects/FluentStringLookup.cs +++ b/Dynamitey/DynamicObjects/FluentStringLookup.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Runtime.Serialization; + using System.Text; using System.Reflection; diff --git a/Dynamitey/DynamicObjects/Get.cs b/Dynamitey/DynamicObjects/Get.cs index 47fe66d..9ab00c5 100644 --- a/Dynamitey/DynamicObjects/Get.cs +++ b/Dynamitey/DynamicObjects/Get.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; + using Dynamitey.Internal.Optimization; using Microsoft.CSharp.RuntimeBinder; @@ -84,7 +84,15 @@ public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, o if (!base.TryInvokeMember(binder, args, out result)) { - result = Dynamic.InvokeGet(CallTarget, binder.Name); + try + { + //Check if there is a get property because it might return a function + result = Dynamic.InvokeGet(CallTarget, binder.Name); + } + catch (RuntimeBinderException) + { + return false; + } if (result == null) return false; var tDel = result as Delegate; diff --git a/Dynamitey/DynamicObjects/LateType.cs b/Dynamitey/DynamicObjects/LateType.cs index cc2f812..e51df89 100644 --- a/Dynamitey/DynamicObjects/LateType.cs +++ b/Dynamitey/DynamicObjects/LateType.cs @@ -3,7 +3,7 @@ using System.Dynamic; using System.Linq; using System.Reflection; -using System.Runtime.Serialization; + using System.Text; using Dynamitey.Internal.Optimization; @@ -54,13 +54,31 @@ public LateType(Type type) } private readonly string TypeName; - + + + public static Type FindType(string typeName, Assembly assembly = null) + { + try + { + if (assembly != null) + { + return assembly.GetType(typeName, false); + } + return Type.GetType(typeName, false); + } + catch + { + return null; + } + } + + /// /// Initializes a new instance of the class. /// /// Qualified Name of the type. public LateType(string typeName) - : base(Type.GetType(typeName, false)) + : base(FindType(typeName)) { TypeName = typeName; @@ -72,7 +90,7 @@ public LateType(string typeName) /// The assembly. /// Name of the type. public LateType(Assembly assembly, string typeName) - : base(assembly.GetType(typeName, false)) + : base(FindType(typeName, assembly)) { TypeName = typeName; diff --git a/Dynamitey/DynamicObjects/Lazy.cs b/Dynamitey/DynamicObjects/Lazy.cs index b0c7a60..7415e4c 100644 --- a/Dynamitey/DynamicObjects/Lazy.cs +++ b/Dynamitey/DynamicObjects/Lazy.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; + namespace Dynamitey.DynamicObjects diff --git a/Dynamitey/DynamicObjects/LinqInstanceProxy.cs b/Dynamitey/DynamicObjects/LinqInstanceProxy.cs index cb9fa5a..b396c61 100644 --- a/Dynamitey/DynamicObjects/LinqInstanceProxy.cs +++ b/Dynamitey/DynamicObjects/LinqInstanceProxy.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; + using System.Text; @@ -21,7 +21,7 @@ public class LinqInstanceProxy : ExtensionToInstanceProxy, IEnumerable /// /// The target. public LinqInstanceProxy(dynamic target) - :base((object)target, typeof(IEnumerable<>), new[]{typeof(Enumerable)}, new[]{typeof(ILinq<>), typeof(IOrderedLinq<>)}) + :base(new InvokeContext(target, typeof(object)), typeof(IEnumerable<>), new[]{typeof(Enumerable)}, new[]{typeof(ILinq<>), typeof(IOrderedLinq<>)}) { } diff --git a/Dynamitey/DynamicObjects/List.cs b/Dynamitey/DynamicObjects/List.cs index a9ab5fb..3103d1f 100644 --- a/Dynamitey/DynamicObjects/List.cs +++ b/Dynamitey/DynamicObjects/List.cs @@ -20,7 +20,7 @@ using System.Dynamic; using System.Linq; using System.Linq.Expressions; -using System.Runtime.Serialization; + using Microsoft.CSharp.RuntimeBinder; namespace Dynamitey.DynamicObjects diff --git a/Dynamitey/DynamicObjects/Mimic.cs b/Dynamitey/DynamicObjects/Mimic.cs index 5966f3f..7e2655c 100644 --- a/Dynamitey/DynamicObjects/Mimic.cs +++ b/Dynamitey/DynamicObjects/Mimic.cs @@ -1,7 +1,7 @@ using System.Dynamic; using System; using System.Reflection; -using System.Runtime.Serialization; + namespace Dynamitey.DynamicObjects diff --git a/Dynamitey/DynamicObjects/Recorder.cs b/Dynamitey/DynamicObjects/Recorder.cs index ed2f562..9563569 100644 --- a/Dynamitey/DynamicObjects/Recorder.cs +++ b/Dynamitey/DynamicObjects/Recorder.cs @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Runtime.Serialization; + using System.Text; using Dynamitey.Internal.Optimization; diff --git a/Dynamitey/DynamicObjects/RegexMatch.cs b/Dynamitey/DynamicObjects/RegexMatch.cs index 29d0a9a..3b8e707 100644 --- a/Dynamitey/DynamicObjects/RegexMatch.cs +++ b/Dynamitey/DynamicObjects/RegexMatch.cs @@ -1,9 +1,11 @@ using System; using System.Dynamic; using System.Linq; -using System.Runtime.Serialization; + using System.Text.RegularExpressions; using System.Collections.Generic; +using System.Reflection; +using Dynamitey.Internal.Compat; namespace Dynamitey.DynamicObjects { @@ -73,7 +75,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) if (!tGroup.Success) { result = null; - if (outType.IsValueType) + if (outType.GetTypeInfo().IsValueType) result = Dynamic.InvokeConstructor(outType); return true; } diff --git a/Dynamitey/Dynamitey.csproj b/Dynamitey/Dynamitey.csproj index 1a686b9..1f046d3 100644 --- a/Dynamitey/Dynamitey.csproj +++ b/Dynamitey/Dynamitey.csproj @@ -1,131 +1,82 @@ - - - - - 10.0 - Debug - AnyCPU - {CE699AB8-4122-4369-BAA6-76244A0734E4} - Library - Properties - Dynamitey - Dynamitey - v4.0 - Profile158 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - Profile47 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\Dynamitey.XML - - - bin\Release.net40\Dynamitey.XML - - - true - + + + netstandard1.5;net40;portable-net45+sl5+win8+wp8 + (pronounced dyna-mighty) flexes DLR muscle to do meta-mazing things in .net + Ekon Benefits + + Copyright 2017 Ekon Benefits + https://github.com/ekonbenefits/dynamitey + http://www.apache.org/licenses/LICENSE-2.0 + dynamic metaprogramming dlr reflection currying tuples expando latetypes + True + True + True + True + True sn.snk + False + + + + + + + + + + + + + + + + + + + - - + TextTemplatingFileGenerator - InlineLambdas1.cs + InlineLambdas.cs - + TextTemplatingFileGenerator InvokeHelper.cs - - + TextTemplatingFileGenerator - ThisFunctions1.cs + ThisFunctions.cs + - - - - - True + + + + + True + True InlineLambdas.tt - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True + True + True InvokeHelper.tt - - - - True + True + True ThisFunctions.tt - + - + - - - - - + + + \ No newline at end of file diff --git a/Dynamitey/Dynamitey.csproj.user b/Dynamitey/Dynamitey.csproj.user index 55f44b9..fe57e57 100644 --- a/Dynamitey/Dynamitey.csproj.user +++ b/Dynamitey/Dynamitey.csproj.user @@ -2,5 +2,6 @@ ShowAllFiles + true \ No newline at end of file diff --git a/Dynamitey/Dynamitey.nuspec b/Dynamitey/Dynamitey.nuspec deleted file mode 100644 index 6755def..0000000 --- a/Dynamitey/Dynamitey.nuspec +++ /dev/null @@ -1,23 +0,0 @@ - - - - $id$ - $version$ - $title$ - $author$ - $author$ - http://www.apache.org/licenses/LICENSE-2.0 - https://github.com/ekonbenefits/dynamitey - - true - $description$ - PCL library - Copyright 2013 - dynamic metaprogramming dlr reflection currying tuples expando latetypes - - - - - - - \ No newline at end of file diff --git a/Dynamitey/InlineLambdas1.cs b/Dynamitey/InlineLambdas.cs similarity index 100% rename from Dynamitey/InlineLambdas1.cs rename to Dynamitey/InlineLambdas.cs diff --git a/Dynamitey/Internal/Compat/Net40.cs b/Dynamitey/Internal/Compat/Net40.cs new file mode 100644 index 0000000..5f6f1f3 --- /dev/null +++ b/Dynamitey/Internal/Compat/Net40.cs @@ -0,0 +1,46 @@ + + + + +namespace Dynamitey.Internal.Compat +{ + + using System; + using System.Collections.Generic; + using System.Reflection; + using System.Text; + using System.Globalization; + using System.Threading; + + public static class Net40 + { +#if NET40 || PROFILE158 + + public static Type GetTypeInfo(this Type type) + { + return type; + } + + public static MethodInfo GetMethodInfo(this Delegate del) + { + return del.Method; + } + + public static CultureInfo GetDefaultThreadCurrentCulture() { + return Thread.CurrentThread.CurrentCulture; + + } +#else + public static CultureInfo GetDefaultThreadCurrentCulture() { + + return CultureInfo.DefaultThreadCurrentCulture; + + } + +#endif + + + } + +} + diff --git a/Dynamitey/Internal/InvokeSetters.cs b/Dynamitey/Internal/InvokeSetters.cs index 4764c22..7cad8b7 100644 --- a/Dynamitey/Internal/InvokeSetters.cs +++ b/Dynamitey/Internal/InvokeSetters.cs @@ -5,7 +5,7 @@ using System.Linq; using Dynamitey.Internal.Optimization; using Microsoft.CSharp.RuntimeBinder; - +using Dynamitey.Internal.Compat; using System.Reflection; namespace Dynamitey.Internal @@ -59,15 +59,15 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re tDict = (IEnumerable>)args[1]; } else if (args[1] is IEnumerable - && args[1].GetType().IsGenericType + && args[1].GetType().GetTypeInfo().IsGenericType ) { var tEnumerableArg = (IEnumerable)args[1]; - var tInterface = tEnumerableArg.GetType().GetInterfaces().FirstOrDefault(it=>it.Name =="IEnumerable`1"); + var tInterface = tEnumerableArg.GetType().GetTypeInfo().GetInterfaces().FirstOrDefault(it=>it.Name =="IEnumerable`1"); if(tInterface !=null) { - var tParamTypes = tInterface.GetGenericArguments(); + var tParamTypes = tInterface.GetTypeInfo().GetGenericArguments(); if(tParamTypes.Length ==1 && tParamTypes[0].GetGenericTypeDefinition() == typeof(Tuple<,>)) { @@ -78,7 +78,7 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re else if (Util.IsAnonymousType(args[1])) { var keyDict = new Dictionary(); - foreach (var tProp in args[1].GetType().GetProperties()) + foreach (var tProp in args[1].GetType().GetTypeInfo().GetProperties()) { keyDict[tProp.Name] = Dynamic.InvokeGet(args[1], tProp.Name); } diff --git a/Dynamitey/Internal/Optimization/InvokeHelper-Regular.cs b/Dynamitey/Internal/Optimization/InvokeHelper-Regular.cs index ca4bb06..e981513 100644 --- a/Dynamitey/Internal/Optimization/InvokeHelper-Regular.cs +++ b/Dynamitey/Internal/Optimization/InvokeHelper-Regular.cs @@ -7,6 +7,7 @@ using Dynamitey.DynamicObjects; using Microsoft.CSharp.RuntimeBinder; using Binder = Microsoft.CSharp.RuntimeBinder.Binder; +using Dynamitey.Internal.Compat; namespace Dynamitey.Internal.Optimization { @@ -17,42 +18,6 @@ internal class DummmyNull } - internal static class BinderCache where T : class - { - internal static readonly IDictionary, CallSite> Cache = new Dictionary, CallSite>(); - - - - - } - - internal static class BinderGetCache where T : class - { - internal static readonly IDictionary, CallSite> - Cache = new Dictionary, CallSite>(); - } - - internal static class BinderConstructorCache where T : class - { - internal static readonly IDictionary, CallSite> Cache = new Dictionary, CallSite>(); - } - - internal static class BinderSetCache where T : class - { - internal static readonly IDictionary, CallSite> Cache = new Dictionary, CallSite>(); - } - - internal static class BinderMemberCache where T : class - { - internal static readonly IDictionary, CallSite> Cache = new Dictionary, CallSite>(); - } - - internal static class BinderDirectCache where T : class - { - internal static readonly IDictionary, CallSite> Cache = new Dictionary, CallSite>(); - } - - internal static partial class InvokeHelper { @@ -63,6 +28,30 @@ internal static partial class InvokeHelper internal const int KnownDirect = 4; internal const int KnownConstructor = 5; + + + private static readonly object _clearDynamicLock = new object(); + internal static IDictionary> DynamicInvokeCreateCallSite + { + get + { + lock (_clearDynamicLock) + { + return _dynamicInvokeCreateCallSite ?? (_dynamicInvokeCreateCallSite = + new Dictionary>()); + } + + } + } + + internal static void ClearFullyDynamicCache() + { + lock (_clearDynamicLock) + { + _dynamicInvokeCreateCallSite = null; + } + } + private static bool TryDynamicCachedCallSite(BinderHash hash, int knownBinderType, out CallSite callSite) where T: class { switch(knownBinderType) @@ -108,33 +97,61 @@ internal static Type EmitCallSiteFuncType(IEnumerable argTypes, Type retur } + internal static HashSet _allCaches = new HashSet(); + private static readonly object _binderCacheLock = new object(); + private static readonly object _callSiteCacheLock = new object(); + internal static IDictionary> _dynamicInvokeCreateCallSite; + + + internal static void ClearAllCaches() + { + lock (_binderCacheLock) + { + foreach (Action instance in _allCaches) + { + instance(); + } + } + + lock (_callSiteCacheLock) + { + ClearFullyDynamicCache(); + } + } + private static void SetDynamicCachedCallSite(BinderHash hash, int knownBinderType, CallSite callSite) where T: class { switch (knownBinderType) { default: + _allCaches.Add(BinderCache.ClearCache); BinderCache.Cache[hash] = callSite; break; case KnownGet: + _allCaches.Add(BinderGetCache.ClearCache); BinderGetCache.Cache[hash] = callSite; break; case KnownSet: + _allCaches.Add(BinderSetCache.ClearCache); BinderSetCache.Cache[hash] = callSite; break; case KnownMember: + _allCaches.Add(BinderMemberCache.ClearCache); BinderMemberCache.Cache[hash] = callSite; break; case KnownDirect: + _allCaches.Add(BinderDirectCache.ClearCache); BinderDirectCache.Cache[hash] = callSite; break; case KnownConstructor: + _allCaches.Add(BinderConstructorCache.ClearCache); BinderConstructorCache.Cache[hash] = callSite; break; } } - private static readonly object _binderCacheLock = new object(); + /// /// LazyBinderType @@ -149,7 +166,7 @@ public static bool IsActionOrFunc(object target) return false; var tType = target as Type ?? target.GetType(); - if (tType.IsGenericType) + if (tType.GetTypeInfo().IsGenericType) { tType = tType.GetGenericTypeDefinition(); } @@ -222,10 +239,10 @@ internal static IEnumerable GetBindingArgumentList(object[] return tList; } - internal static readonly IDictionary> - _dynamicInvokeCreateCallSite = new Dictionary>(); - private static readonly object _callSiteCacheLock = new object(); + + + internal static CallSite CreateCallSite( Type delegateType, @@ -246,7 +263,7 @@ internal static CallSite CreateCallSite( lock (_callSiteCacheLock) { - foundInCache = _dynamicInvokeCreateCallSite.TryGetValue(delegateType, out tSite); + foundInCache = DynamicInvokeCreateCallSite.TryGetValue(delegateType, out tSite); } if (!foundInCache) @@ -276,9 +293,9 @@ internal static CallSite CreateCallSite( lock (_callSiteCacheLock) { // another thread might have been faster; add to dictionary only if we are the first - if (!_dynamicInvokeCreateCallSite.ContainsKey(delegateType)) + if (!DynamicInvokeCreateCallSite.ContainsKey(delegateType)) { - _dynamicInvokeCreateCallSite[delegateType] = tSite; + DynamicInvokeCreateCallSite[delegateType] = tSite; } } } @@ -429,12 +446,8 @@ internal static object InvokeGetCallSite(object target, string name, Type contex if (staticContext) //CSharp Binder won't call Static properties, grrr. { var tStaticFlag = CSharpBinderFlags.None; - if ((target is Type && ((Type)target).IsPublic) || Util.IsMono) + if ((target is Type && ((Type)target).GetTypeInfo().IsPublic)) { - //Mono only works if InvokeSpecialName is set and .net only works if it isn't - if (Util.IsMono) - tStaticFlag |= CSharpBinderFlags.InvokeSpecialName; - tBinder = () => Binder.InvokeMember(tStaticFlag, "get_" + name, null, context, @@ -498,8 +511,6 @@ internal static object InvokeSetCallSite(object target, string name, object valu tBinder = () =>{ var tStaticFlag = CSharpBinderFlags.ResultDiscarded; - if (Util.IsMono) //Mono only works if InvokeSpecialName is set and .net only works if it isn't - tStaticFlag |= CSharpBinderFlags.InvokeSpecialName; return Binder.InvokeMember(tStaticFlag, "set_" + name, null, @@ -794,7 +805,7 @@ internal static object InvokeConstructorCallSite(Type type, bool isValueType, ob } - if (isValueType || Util.IsMono) + if (isValueType) { CallSite tDummy =null; return DynamicInvokeStaticMember(type, ref tDummy, tBinderType, KnownConstructor, tBinder, ConstructorName, true, type, @@ -820,15 +831,8 @@ internal static Delegate WrapFunc(Type returnType, object invokable, int length) if (!_dynamicInvokeWrapFunc.TryGetValue(returnType, out tSite)) { - var tMethod = "WrapFuncHelperMono"; - -#if !__MonoCS__ - //Mono Compiler can't compile or run WrapFuncHelper - if (!Util.IsMono) - { - tMethod = "WrapFuncHelper"; - } -#endif + var tMethod = "WrapFuncHelper"; + tSite = CallSite.Create( Binder.InvokeMember( CSharpBinderFlags.None, diff --git a/Dynamitey/Internal/Optimization/InvokeHelper.cs b/Dynamitey/Internal/Optimization/InvokeHelper.cs index 57e0bab..eaf630f 100644 --- a/Dynamitey/Internal/Optimization/InvokeHelper.cs +++ b/Dynamitey/Internal/Optimization/InvokeHelper.cs @@ -20,9 +20,159 @@ using System.Runtime.CompilerServices; using System.Reflection; -namespace Dynamitey.Internal.Optimization -{ - +namespace Dynamitey.Internal.Optimization { + + + internal static class BinderCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } + internal static class BinderGetCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } + internal static class BinderSetCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } + internal static class BinderConstructorCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } + internal static class BinderMemberCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } + internal static class BinderDirectCache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } internal static partial class InvokeHelper { @@ -475,7 +625,6 @@ internal static TReturn InvokeMemberTargetType( - #if !__MonoCS__ internal static Delegate WrapFuncHelper(dynamic invokable, int length) { switch(length){ @@ -519,109 +668,6 @@ internal static Delegate WrapFuncHelper(dynamic invokable, int length) return new DynamicFunc(args=>(TReturn)Dynamic.Invoke((object)invokable,args)); } } - #endif - - internal static class MonoConvertCallSite{ - internal static CallSite CallSite; - } - - internal static Delegate WrapFuncHelperMono(dynamic invokable, int length) - { - switch(length){ -#region Optimizations - case 0: - return new Func< TReturn>(()=>{ - object tResult= invokable(); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 1: - return new Func< object, TReturn>((a1)=>{ - object tResult= invokable(a1); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 2: - return new Func< object, object, TReturn>((a1,a2)=>{ - object tResult= invokable(a1,a2); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 3: - return new Func< object, object, object, TReturn>((a1,a2,a3)=>{ - object tResult= invokable(a1,a2,a3); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 4: - return new Func< object, object, object, object, TReturn>((a1,a2,a3,a4)=>{ - object tResult= invokable(a1,a2,a3,a4); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 5: - return new Func< object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5)=>{ - object tResult= invokable(a1,a2,a3,a4,a5); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 6: - return new Func< object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 7: - return new Func< object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 8: - return new Func< object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 9: - return new Func< object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 10: - return new Func< object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 11: - return new Func< object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 12: - return new Func< object, object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 13: - return new Func< object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 14: - return new Func< object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 15: - return new Func< object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - case 16: - return new Func< object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn>((a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)=>{ - object tResult= invokable(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); -#endregion - default: - return new DynamicFunc(args=>{ - object tResult= Dynamic.Invoke((object)invokable,args); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - } - } internal static Delegate WrapAction(dynamic invokable, int length) diff --git a/Dynamitey/Internal/Optimization/InvokeHelper.tt b/Dynamitey/Internal/Optimization/InvokeHelper.tt index bf236e8..e5cde6b 100644 --- a/Dynamitey/Internal/Optimization/InvokeHelper.tt +++ b/Dynamitey/Internal/Optimization/InvokeHelper.tt @@ -24,9 +24,37 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Reflection; -namespace Dynamitey.Internal.Optimization -{ - +namespace Dynamitey.Internal.Optimization { + +<# var cacheTypes = new []{"", "Get", "Set", "Constructor", "Member", "Direct"}; #> + +<# foreach(var name in cacheTypes){ #> + internal static class Binder<#=name#>Cache where T : class + { + private static IDictionary, CallSite> _cache; + + private static readonly object _cacheLock = new object(); + + internal static IDictionary, CallSite> Cache + { + get + { + lock (_cacheLock) + { + return _cache ?? (_cache = new Dictionary, CallSite>()); + } + } + } + + internal static readonly Action ClearCache = () => + { + lock (_cacheLock) + { + _cache = null; + } + }; + } +<# } #> internal static partial class InvokeHelper { @@ -187,7 +215,6 @@ namespace Dynamitey.Internal.Optimization - #if !__MonoCS__ internal static Delegate WrapFuncHelper(dynamic invokable, int length) { switch(length){ @@ -203,34 +230,6 @@ namespace Dynamitey.Internal.Optimization return new DynamicFunc(args=>(TReturn)Dynamic.Invoke((object)invokable,args)); } } - #endif - - internal static class MonoConvertCallSite{ - internal static CallSite CallSite; - } - - internal static Delegate WrapFuncHelperMono(dynamic invokable, int length) - { - switch(length){ -#region Optimizations - <# for(int i=0; i <= 16; i++){ - var tobjectArgs = String.Join(",",Enumerable.Repeat(" object",i).Concat(new[]{" TReturn"})); - var tArgList = String.Join(",",Enumerable.Range(0,i).Select(it=>"a"+(it+1))); -#> case <#=i#>: - return new Func<<#=tobjectArgs#>>((<#=tArgList#>)=>{ - object tResult= invokable(<#=tArgList#>); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); -<# } #> -#endregion - default: - return new DynamicFunc(args=>{ - object tResult= Dynamic.Invoke((object)invokable,args); - return (TReturn) InvokeConvertCallSite(tResult, true, typeof(TReturn), typeof(object), ref MonoConvertCallSite.CallSite); - }); - } - } - internal static Delegate WrapAction(dynamic invokable, int length) { diff --git a/Dynamitey/Internal/Optimization/Util.cs b/Dynamitey/Internal/Optimization/Util.cs index a0e4150..760f374 100644 --- a/Dynamitey/Internal/Optimization/Util.cs +++ b/Dynamitey/Internal/Optimization/Util.cs @@ -21,11 +21,9 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.Serialization; -using System.Threading; using Dynamitey.DynamicObjects; using Microsoft.CSharp.RuntimeBinder; - +using Dynamitey.Internal.Compat; namespace Dynamitey.Internal.Optimization @@ -62,10 +60,9 @@ public static bool IsAnonymousType(object target) return false; var type = target as Type ?? target.GetType(); - - return type.IsNotPublic - && Attribute.IsDefined( - type, + var typeinfo = type.GetTypeInfo(); + return typeinfo.IsNotPublic + && typeinfo.IsDefined( typeof(CompilerGeneratedAttribute), false); } @@ -161,12 +158,12 @@ internal static bool MassageResultBasedOnInterface(this BaseObject target, strin return false; } - if (typeof (Delegate).IsAssignableFrom(tType)) + if (typeof (Delegate).GetTypeInfo().IsAssignableFrom(tType)) { result = new BaseForwarder.AddRemoveMarker(); } - if (tType.IsValueType) + if (tType.GetTypeInfo().IsValueType) { result = Dynamic.InvokeConstructor(tType); } diff --git a/Dynamitey/PartialApply.cs b/Dynamitey/PartialApply.cs index dce7da2..ccddc69 100644 --- a/Dynamitey/PartialApply.cs +++ b/Dynamitey/PartialApply.cs @@ -4,7 +4,7 @@ using System.Dynamic; using System.Linq; using System.Linq.Expressions; -using System.Runtime.Serialization; + using System.Text; using System.Reflection; using Dynamitey.Internal.Optimization; diff --git a/Dynamitey/Properties/AssemblyInfo.cs b/Dynamitey/Properties/AssemblyInfo.cs deleted file mode 100644 index c85d60b..0000000 --- a/Dynamitey/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Dynamitey")] -[assembly: AssemblyDescription("(pronounced dyna-mighty) flexes DLR muscle to do meta-mazing things in .net")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Ekon Benefits")] -[assembly: AssemblyProduct("Dynamitey")] -[assembly: AssemblyCopyright("Copyright © EkonBenefits 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3")] diff --git a/Dynamitey/ThisFunctions1.cs b/Dynamitey/ThisFunctions.cs similarity index 99% rename from Dynamitey/ThisFunctions1.cs rename to Dynamitey/ThisFunctions.cs index 7cde5b5..6498c7f 100644 --- a/Dynamitey/ThisFunctions1.cs +++ b/Dynamitey/ThisFunctions.cs @@ -15,6 +15,8 @@ using System; using System.Collections.Generic; +using System.Reflection; +using Dynamitey.Internal.Compat; namespace Dynamitey { @@ -219,7 +221,7 @@ public static class ThisDelegate{ /// public static bool IsSpecialThisDelegate(this Delegate del){ var tType =del.GetType(); - if(!tType.IsGenericType) return false; + if(!tType.GetTypeInfo().IsGenericType) return false; var tGenDel =del.GetType().GetGenericTypeDefinition(); var tReturn =_specialThisDels.Contains(tGenDel); return tReturn; diff --git a/Dynamitey/ThisFunctions.tt b/Dynamitey/ThisFunctions.tt index 823d360..c3589ed 100644 --- a/Dynamitey/ThisFunctions.tt +++ b/Dynamitey/ThisFunctions.tt @@ -19,6 +19,8 @@ using System; using System.Collections.Generic; +using System.Reflection; +using Dynamitey.Internal.Compat; namespace Dynamitey { @@ -75,7 +77,7 @@ namespace Dynamitey /// public static bool IsSpecialThisDelegate(this Delegate del){ var tType =del.GetType(); - if(!tType.IsGenericType) return false; + if(!tType.GetTypeInfo().IsGenericType) return false; var tGenDel =del.GetType().GetGenericTypeDefinition(); var tReturn =_specialThisDels.Contains(tGenDel); return tReturn; diff --git a/Dynamitey/Tupler.cs b/Dynamitey/Tupler.cs index 338d7b1..a9eb23a 100644 --- a/Dynamitey/Tupler.cs +++ b/Dynamitey/Tupler.cs @@ -17,9 +17,11 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using Dynamitey.DynamicObjects; using Dynamitey.Internal.Optimization; +using Dynamitey.Internal.Compat; namespace Dynamitey { @@ -194,7 +196,7 @@ private static bool HelperIsTuple(object target, out Type type, out Type generic type = target as Type ?? target.GetType(); - if (safe || type.IsGenericType) + if (safe || type.GetTypeInfo().IsGenericType) { genericeType = type.GetGenericTypeDefinition(); } @@ -222,7 +224,7 @@ private static int HelperSize(object tuple, bool safe) { if (size == 8) { - var lasttype = type.GetGenericArguments()[7]; + var lasttype = type.GetTypeInfo().GetGenericArguments()[7]; size = size + HelperSize(lasttype, true) - 1; } } diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000..d1e2b59 --- /dev/null +++ b/NuGet.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Readme.md b/Readme.md index 7e3626f..aa3008e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,24 @@ -# Dynamitey [![Build Status](https://travis-ci.org/ekonbenefits/dynamitey.png?branch=master)](https://travis-ci.org/ekonbenefits/dynamitey) +# Dynamitey (pronounced dyna-mighty) flexes DLR muscle to do meta-mazing things in .net -This is a Portable Class Library for .NET 4.5, Silverlight 4 & 5, WinRT, Win Phone 8; And .net 4.0 Library +Dynamitey is available Nuget [![NuGet](https://img.shields.io/nuget/dt/Dynamitey.svg)](https://www.nuget.org/packages/Dynamitey/) + +You can find the latest bleed edge on MyGet [![MyGet Pre Release](https://img.shields.io/myget/dynamitey-ci/vpre/Dynamitey.svg)](https://www.myget.org/feed/dynamitey-ci/package/nuget/Dynamitey) + +Platform | Status +-------- | ------ +Windows | [![Build status](https://ci.appveyor.com/api/projects/status/kctdnnmctakj1j9w/branch/master?svg=true)](https://ci.appveyor.com/project/jbtule/dynamitey/branch/master) +Mac | [![Build Status](https://travis-matrix-badges.herokuapp.com/repos/ekonbenefits/dynamitey/branches/master/2)](https://travis-ci.org/ekonbenefits/dynamitey) +Linux | [![Build Status](https://travis-matrix-badges.herokuapp.com/repos/ekonbenefits/dynamitey/branches/master/1)](https://travis-ci.org/ekonbenefits/dynamitey) + +Compiled For| +--------| +.Net Std 1.5 | +.Net 4.0 | +Portable .NET 4.5, Silverlight 4 & 5, WinRT, Win Phone 8 | + + [Change Log](https://github.com/ekonbenefits/dynamitey/wiki/ChangeLog) @@ -19,4 +35,4 @@ PM> Install-Package Dynamitey - Manipulation of Tuples -- [wowzers](https://github.com/ekonbenefits/dynamitey/blob/master/Tests/TuplerTest.cs) - Inline Object Graph Intialization Syntax [whoa](https://github.com/ekonbenefits/dynamitey/wiki/UsageBuilder) - DynamicObject base types for many things -- [jenkies](https://github.com/ekonbenefits/dynamitey/wiki/UsageDynamic) - - Extension to instance method conversion -- [o_O] (https://github.com/ekonbenefits/dynamitey/blob/master/Tests/Linq.cs) + - Extension to instance method conversion -- [o_O](https://github.com/ekonbenefits/dynamitey/blob/master/Tests/Linq.cs) diff --git a/SupportLibrary/SupportLibrary.csproj b/SupportLibrary/SupportLibrary.csproj new file mode 100644 index 0000000..12d51c4 --- /dev/null +++ b/SupportLibrary/SupportLibrary.csproj @@ -0,0 +1,13 @@ + + + + netstandard1.0 + + + + + + + + + \ No newline at end of file diff --git a/SupportLibrary1/SupportTypes.cs b/SupportLibrary/SupportTypes.cs similarity index 97% rename from SupportLibrary1/SupportTypes.cs rename to SupportLibrary/SupportTypes.cs index c84a922..a7c3a01 100644 --- a/SupportLibrary1/SupportTypes.cs +++ b/SupportLibrary/SupportTypes.cs @@ -6,7 +6,7 @@ using System.Text; using Dynamitey; -namespace Dynamitey.SupportLibrary1 +namespace Dynamitey.SupportLibrary { public class TestEvent { @@ -308,7 +308,7 @@ public class VoidMethodPoco { public void Action() { - + } } @@ -366,6 +366,16 @@ List GetThings(Guid test) where T : Thing } + public class ForwardGenericMethodsTestClass + { + public string Value { get; set; } + + public T Create(int arg) where T : ForwardGenericMethodsTestClass, new() + { + return new T { Value = "test" + arg }; + } + } + public class GenericMethOutPoco { diff --git a/SupportLibrary1/Properties/AssemblyInfo.cs b/SupportLibrary1/Properties/AssemblyInfo.cs deleted file mode 100644 index 3f31f9a..0000000 --- a/SupportLibrary1/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SupportLibrary1")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SupportLibrary1")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SupportLibrary1/SupportLibrary1.csproj b/SupportLibrary1/SupportLibrary1.csproj deleted file mode 100644 index 59b4836..0000000 --- a/SupportLibrary1/SupportLibrary1.csproj +++ /dev/null @@ -1,52 +0,0 @@ - - - - - 10.0 - Debug - AnyCPU - {348152A9-6A9C-4115-B60A-9E08CA72451D} - Library - Properties - SupportLibrary1 - SupportLibrary1 - v4.0 - Profile158 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - Profile47 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - \ No newline at end of file diff --git a/TestResult.xml b/TestResult.xml new file mode 100644 index 0000000..ca09dc5 --- /dev/null +++ b/TestResult.xml @@ -0,0 +1,800 @@ + + + + + + Performance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + :IEnumerable +{ + TSource Aggregate(Func func); + TAccumulate Aggregate(TAccumulate seed,Func func); + TResult Aggregate(TAccumulate seed,Func func,Func resultSelector); + Boolean All(Func predicate); + Boolean Any(); + Boolean Any(Func predicate); + ILinq Append(TSource element); + ILinq AsEnumerable(); + Double Average(Func selector); + Nullable Average(Func> selector); + Double Average(Func selector); + Nullable Average(Func> selector); + Single Average(Func selector); + Nullable Average(Func> selector); + Double Average(Func selector); + Nullable Average(Func> selector); + Decimal Average(Func selector); + Nullable Average(Func> selector); + ILinq Cast(); + ILinq Concat(IEnumerable second); + Boolean Contains(TSource value); + Boolean Contains(TSource value,IEqualityComparer comparer); + Int32 Count(); + Int32 Count(Func predicate); + ILinq DefaultIfEmpty(); + ILinq DefaultIfEmpty(TSource defaultValue); + ILinq Distinct(); + ILinq Distinct(IEqualityComparer comparer); + TSource ElementAt(Int32 index); + TSource ElementAtOrDefault(Int32 index); + ILinq Except(IEnumerable second); + ILinq Except(IEnumerable second,IEqualityComparer comparer); + TSource First(); + TSource First(Func predicate); + TSource FirstOrDefault(); + TSource FirstOrDefault(Func predicate); + ILinq> GroupBy(Func keySelector); + ILinq> GroupBy(Func keySelector,IEqualityComparer comparer); + ILinq> GroupBy(Func keySelector,Func elementSelector); + ILinq> GroupBy(Func keySelector,Func elementSelector,IEqualityComparer comparer); + ILinq GroupBy(Func keySelector,Func,TResult> resultSelector); + ILinq GroupBy(Func keySelector,Func elementSelector,Func,TResult> resultSelector); + ILinq GroupBy(Func keySelector,Func,TResult> resultSelector,IEqualityComparer comparer); + ILinq GroupBy(Func keySelector,Func elementSelector,Func,TResult> resultSelector,IEqualityComparer comparer); + ILinq GroupJoin(IEnumerable inner,Func outerKeySelector,Func innerKeySelector,Func,TResult> resultSelector); + ILinq GroupJoin(IEnumerable inner,Func outerKeySelector,Func innerKeySelector,Func,TResult> resultSelector,IEqualityComparer comparer); + ILinq Intersect(IEnumerable second); + ILinq Intersect(IEnumerable second,IEqualityComparer comparer); + ILinq Join(IEnumerable inner,Func outerKeySelector,Func innerKeySelector,Func resultSelector); + ILinq Join(IEnumerable inner,Func outerKeySelector,Func innerKeySelector,Func resultSelector,IEqualityComparer comparer); + TSource Last(); + TSource Last(Func predicate); + TSource LastOrDefault(); + TSource LastOrDefault(Func predicate); + Int64 LongCount(); + Int64 LongCount(Func predicate); + TSource Max(); + Int32 Max(Func selector); + Nullable Max(Func> selector); + Int64 Max(Func selector); + Nullable Max(Func> selector); + Single Max(Func selector); + Nullable Max(Func> selector); + Double Max(Func selector); + Nullable Max(Func> selector); + Decimal Max(Func selector); + Nullable Max(Func> selector); + TResult Max(Func selector); + TSource Min(); + Int32 Min(Func selector); + Nullable Min(Func> selector); + Int64 Min(Func selector); + Nullable Min(Func> selector); + Single Min(Func selector); + Nullable Min(Func> selector); + Double Min(Func selector); + Nullable Min(Func> selector); + Decimal Min(Func selector); + Nullable Min(Func> selector); + TResult Min(Func selector); + ILinq OfType(); + IOrderedLinq OrderBy(Func keySelector); + IOrderedLinq OrderBy(Func keySelector,IComparer comparer); + IOrderedLinq OrderByDescending(Func keySelector); + IOrderedLinq OrderByDescending(Func keySelector,IComparer comparer); + ILinq Prepend(TSource element); + ILinq Reverse(); + ILinq Select(Func selector); + ILinq Select(Func selector); + ILinq SelectMany(Func> selector); + ILinq SelectMany(Func> selector); + ILinq SelectMany(Func> collectionSelector,Func resultSelector); + ILinq SelectMany(Func> collectionSelector,Func resultSelector); + Boolean SequenceEqual(IEnumerable second); + Boolean SequenceEqual(IEnumerable second,IEqualityComparer comparer); + TSource Single(); + TSource Single(Func predicate); + TSource SingleOrDefault(); + TSource SingleOrDefault(Func predicate); + ILinq Skip(Int32 count); + ILinq SkipLast(Int32 count); + ILinq SkipWhile(Func predicate); + ILinq SkipWhile(Func predicate); + Int32 Sum(Func selector); + Nullable Sum(Func> selector); + Int64 Sum(Func selector); + Nullable Sum(Func> selector); + Single Sum(Func selector); + Nullable Sum(Func> selector); + Double Sum(Func selector); + Nullable Sum(Func> selector); + Decimal Sum(Func selector); + Nullable Sum(Func> selector); + ILinq Take(Int32 count); + ILinq TakeLast(Int32 count); + ILinq TakeWhile(Func predicate); + ILinq TakeWhile(Func predicate); + TSource[] ToArray(); + Dictionary ToDictionary(Func keySelector); + Dictionary ToDictionary(Func keySelector,IEqualityComparer comparer); + Dictionary ToDictionary(Func keySelector,Func elementSelector); + Dictionary ToDictionary(Func keySelector,Func elementSelector,IEqualityComparer comparer); + HashSet ToHashSet(); + HashSet ToHashSet(IEqualityComparer comparer); + List ToList(); + ILookup ToLookup(Func keySelector); + ILookup ToLookup(Func keySelector,IEqualityComparer comparer); + ILookup ToLookup(Func keySelector,Func elementSelector); + ILookup ToLookup(Func keySelector,Func elementSelector,IEqualityComparer comparer); + ILinq Union(IEnumerable second); + ILinq Union(IEnumerable second,IEqualityComparer comparer); + ILinq Where(Func predicate); + ILinq Where(Func predicate); + ILinq Zip(IEnumerable second,Func resultSelector); +} + +public interface IOrderedLinq : ILinq, IOrderedEnumerable +{ + IOrderedLinq ThenBy(Func keySelector); + IOrderedLinq ThenBy(Func keySelector,IComparer comparer); + IOrderedLinq ThenByDescending(Func keySelector); + IOrderedLinq ThenByDescending(Func keySelector,IComparer comparer); +} + +//Skipped Methods +//Double Average(IEnumerable source); +//Nullable Average(IEnumerable> source); +//Double Average(IEnumerable source); +//Nullable Average(IEnumerable> source); +//Single Average(IEnumerable source); +//Nullable Average(IEnumerable> source); +//Double Average(IEnumerable source); +//Nullable Average(IEnumerable> source); +//Decimal Average(IEnumerable source); +//Nullable Average(IEnumerable> source); +//Int32 Max(IEnumerable source); +//Nullable Max(IEnumerable> source); +//Int64 Max(IEnumerable source); +//Nullable Max(IEnumerable> source); +//Double Max(IEnumerable source); +//Nullable Max(IEnumerable> source); +//Single Max(IEnumerable source); +//Nullable Max(IEnumerable> source); +//Decimal Max(IEnumerable source); +//Nullable Max(IEnumerable> source); +//Int32 Min(IEnumerable source); +//Nullable Min(IEnumerable> source); +//Int64 Min(IEnumerable source); +//Nullable Min(IEnumerable> source); +//Single Min(IEnumerable source); +//Nullable Min(IEnumerable> source); +//Double Min(IEnumerable source); +//Nullable Min(IEnumerable> source); +//Decimal Min(IEnumerable source); +//Nullable Min(IEnumerable> source); +//ILinq Range(Int32 start,Int32 count); +//ILinq Repeat(TResult element,Int32 count); +//Int32 Sum(IEnumerable source); +//Nullable Sum(IEnumerable> source); +//Int64 Sum(IEnumerable source); +//Nullable Sum(IEnumerable> source); +//Single Sum(IEnumerable source); +//Nullable Sum(IEnumerable> source); +//Double Sum(IEnumerable source); +//Nullable Sum(IEnumerable> source); +//Decimal Sum(IEnumerable source); +//Nullable Sum(IEnumerable> source); +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Curry.cs b/Tests/Curry.cs index ca2c408..50cad72 100644 --- a/Tests/Curry.cs +++ b/Tests/Curry.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; using NUnit.Framework; namespace Dynamitey.Tests @@ -288,7 +288,7 @@ public void CurryLeftPipeTest() var curried = Dynamic.Curry(adder); - Assert.That(curried << "1" << "2" << "3", Is.EqualTo("123")); + Assert.That((object)(curried << "1" << "2" << "3"), Is.EqualTo("123")); } @@ -300,7 +300,7 @@ public void CurryRightPipeTest() var curried = Dynamic.Curry(adder); - Assert.That( "1" | ( "2" | ("3" | curried)), Is.EqualTo("321")); + Assert.That((object) ("1" | ( "2" | ("3" | curried))), Is.EqualTo("321")); } } } diff --git a/Tests/DynamicObjects.cs b/Tests/DynamicObjects.cs index fc42c86..a0ae772 100644 --- a/Tests/DynamicObjects.cs +++ b/Tests/DynamicObjects.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; using Microsoft.CSharp; using NUnit.Framework; @@ -133,6 +133,16 @@ public void ForwardVoidTest() } + [Test] + public void ForwardGenericMethodsTest() + { + dynamic tNew = new ForwardGenericMethodsTestClass(); + + dynamic tFwd = new TestForwarder(tNew); + + Assert.AreEqual("test99", tFwd.Create(99).Value); + } + [Test] public void ForwardDynamicTest() @@ -167,9 +177,9 @@ public void DictionaryMethodsTest() Assert.That(() => tNew.Action1(), Throws.InstanceOf()); Assert.That(() => tNew.Action2(true), Throws.InstanceOf()); - Assert.That(tNew.Action3(), Is.EqualTo("test")); + Assert.That((object)tNew.Action3(), Is.EqualTo("test")); - Assert.That(tNew.Action4(4), Is.EqualTo("test4")); + Assert.That((object)tNew.Action4(4), Is.EqualTo("test4")); } [Test] @@ -190,9 +200,9 @@ public void ForwardMethodsTest() Assert.That(() => tFwd.Action1(), Throws.InstanceOf()); Assert.That(() => tFwd.Action2(true), Throws.InstanceOf()); - Assert.That(tFwd.Action3(), Is.EqualTo("test")); + Assert.That((object)tFwd.Action3(), Is.EqualTo("test")); - Assert.That(tFwd.Action4(4), Is.EqualTo("test4")); + Assert.That((object)tFwd.Action4(4), Is.EqualTo("test4")); } [Test] @@ -247,7 +257,7 @@ public void DictionaryNullMethodsTest() dynamic tNew = new DynamicObjects.Dictionary(); Dynamic.ApplyEquivalentType(tNew, typeof (ISimpleStringMethod)); - Assert.That(tNew.StartsWith("Te"), Is.False); + Assert.That((object)tNew.StartsWith("Te"), Is.False); @@ -399,7 +409,7 @@ public void TestAnonInterface() Assert.AreEqual(10, tInterface.Count); Assert.AreEqual(false, tInterface.IsSynchronized); Assert.AreEqual(this, tInterface.SyncRoot); - Assert.That(tInterface.GetEnumerator(), Is.InstanceOf()); + Assert.That((object)tInterface.GetEnumerator(), Is.InstanceOf()); } [Test] @@ -566,7 +576,7 @@ public void TestRecorder() } - +#if !NETCOREAPP2_0 [Test] public void TestCodeDomLateTypeBind() @@ -597,7 +607,7 @@ public static string Concatenate(string s1, string s2){ } - +#endif [Test] diff --git a/Tests/Impromptu.cs b/Tests/Impromptu.cs index d15afd3..b51d333 100644 --- a/Tests/Impromptu.cs +++ b/Tests/Impromptu.cs @@ -5,11 +5,12 @@ using System.Threading.Tasks; using NUnit.Framework; using Dynamitey; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; +using ImpromptuInterface; namespace Dynamitey.Tests { - [TestFixture] + [TestFixture(Category = "Impromptu")] public class Impromptu:AssertionHelper { @@ -43,20 +44,6 @@ public void DictionaryCurriedAcctlikeNullMethodsTest() - } - - [Test] - public void DictionaryInterfaceGetServiceNullMethodsTest() - { - - var provider = new DynamicObjects.Dictionary() as IServiceProvider; - - var actsLike = (ISimpleStringMethod)provider.GetService(typeof(ISimpleStringMethod)); - - Assert.AreEqual(false, actsLike.StartsWith("Te")); - - - } public interface IBuilder diff --git a/Tests/Invoke.cs b/Tests/Invoke.cs index 5279a36..a23adfe 100644 --- a/Tests/Invoke.cs +++ b/Tests/Invoke.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Text; using System.Xml.Linq; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; using Microsoft.CSharp.RuntimeBinder; using Moq; using NUnit.Framework; @@ -15,6 +15,13 @@ namespace Dynamitey.Tests { public class Invoke:AssertionHelper { + [TestFixtureTearDown] + public void DestroyCaches() + { + Dynamic.ClearCaches(); + } + + [Test] public void TestDynamicSet() { @@ -342,8 +349,8 @@ public void TestCoerceConverterColor() var color =Dynamic.CoerceConvert(colorString, typeof (Color)); - Assert.That(color,Is.TypeOf()); - Assert.That(color, Is.EqualTo(Color.PaleVioletRed)); + Assert.That((object)color,Is.TypeOf()); + Assert.That((object)color, Is.EqualTo(Color.PaleVioletRed)); } @@ -1353,6 +1360,36 @@ private DynamicObject CreateMock(ExpressionType op) return tMock.Object; } + public class OperatorTestDynObject:DynamicObject{ + ExpressionType _type; + public OperatorTestDynObject(ExpressionType type){ + _type = type; + } + + public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result){ + Assert.AreEqual(_type, binder.Operation); + result = _type; + return true; + } + + public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result){ + Assert.AreEqual(_type, binder.Operation); + result = _type; + return true; + } + + } + private void RunBinaryMockTests(ExpressionType type){ + var mock = new OperatorTestDynObject(type); + var dummy = new Object(); + Dynamic.InvokeBinaryOperator(mock, type, dummy); + } + + private void RunUnaryMockTests(ExpressionType type){ + var mock = new OperatorTestDynObject(type); + Dynamic.InvokeUnaryOpartor(type,mock); + } + [Test] public void TestInvokeAdd() { @@ -1360,28 +1397,51 @@ public void TestInvokeAdd() } [Test] - public void TestInvokeAddDynamic() + public void TestInvokeBasicUnaryOperatorsDynamic() { - var tMock = CreateMock(ExpressionType.Add); - Dynamic.InvokeBinaryOperator(tMock, ExpressionType.Add, 4); - } + RunUnaryMockTests(ExpressionType.Not); + RunUnaryMockTests(ExpressionType.Negate); + RunUnaryMockTests(ExpressionType.Increment); + RunUnaryMockTests(ExpressionType.Decrement); + + + } [Test] - public void TestInvokeSubtract() + public void TestInvokeBasicBinaryOperatorsDynamic() { - Assert.AreEqual(Dynamic.InvokeBinaryOperator(1, ExpressionType.Subtract, 2), -1); + RunBinaryMockTests(ExpressionType.Add); + RunBinaryMockTests(ExpressionType.Subtract); + RunBinaryMockTests(ExpressionType.Divide); + RunBinaryMockTests(ExpressionType.Multiply); + RunBinaryMockTests(ExpressionType.Modulo); + + RunBinaryMockTests(ExpressionType.And); + RunBinaryMockTests(ExpressionType.Or); + RunBinaryMockTests(ExpressionType.ExclusiveOr); + RunBinaryMockTests(ExpressionType.LeftShift); + RunBinaryMockTests(ExpressionType.RightShift); + + RunBinaryMockTests(ExpressionType.AddAssign); + RunBinaryMockTests(ExpressionType.SubtractAssign); + RunBinaryMockTests(ExpressionType.DivideAssign); + RunBinaryMockTests(ExpressionType.MultiplyAssign); + RunBinaryMockTests(ExpressionType.ModuloAssign); + + RunBinaryMockTests(ExpressionType.AndAssign); + RunBinaryMockTests(ExpressionType.OrAssign); + RunBinaryMockTests(ExpressionType.ExclusiveOrAssign); + RunBinaryMockTests(ExpressionType.LeftShiftAssign); + RunBinaryMockTests(ExpressionType.RightShiftAssign); } [Test] - public void TestInvokeSubtractDynamic() + public void TestInvokeSubtract() { - var tType = ExpressionType.Subtract; - var tMock = CreateMock(tType); - Dynamic.InvokeBinaryOperator(tMock, tType, 4); + Assert.AreEqual(Dynamic.InvokeBinaryOperator(1, ExpressionType.Subtract, 2), -1); } - } } diff --git a/Tests/Linq.cs b/Tests/Linq.cs index 9ae97a1..137ba77 100644 --- a/Tests/Linq.cs +++ b/Tests/Linq.cs @@ -5,10 +5,11 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; +using NUnit.Framework; +#if !NETCOREAPP2_0 using IronPython.Hosting; using Microsoft.Scripting; -using NUnit.Framework; - +#endif namespace Dynamitey.Tests { [TestFixture] @@ -36,9 +37,10 @@ public void MoreGenericsDynamicLinq() Assert.AreEqual(expected, actual); } - +#if !NETCOREAPP2_0 private dynamic RunPythonHelper(object linq, string code) { + var tEngine = Python.CreateEngine(); var tScope = tEngine.CreateScope(); @@ -51,7 +53,15 @@ private dynamic RunPythonHelper(object linq, string code) tCompiled.Execute(tScope); return tScope.GetVariable("result"); } +#else + private dynamic RunPythonHelper(object linq, string code) + { + + Assert.Ignore("Iron Python Doesn't work on .net core"); + return new object(); + } +#endif diff --git a/Tests/MimicTest.cs b/Tests/MimicTest.cs index 616eeed..896bc49 100644 --- a/Tests/MimicTest.cs +++ b/Tests/MimicTest.cs @@ -27,7 +27,7 @@ public void Get_Property() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic.I.Can.Get.Any.Property.I.Want.And.It.Wont.Blow.Up; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] @@ -35,7 +35,7 @@ public void Set_Property() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic.I.Can.Set.Any.Property.I.Want.And.It.Wont.Blow = "Up"; - Assert.That(result, Is.EqualTo("Up")); + Assert.That((object)result, Is.EqualTo("Up")); } [Test] @@ -43,7 +43,7 @@ public void Call_Method() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic.I.Can.Call.Any.Method.I.Want.And.It.Wont.Blow.Up(); - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] @@ -51,7 +51,7 @@ public void Call_Method_With_Parameters() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic.I().Can().Call().Any().Method().I().Want().And().It().Wont().Blow().Up("And", "Any", "Parameter", "I", "Want", 1, 2, 3, 44.99m); - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] @@ -59,7 +59,7 @@ public void Get_Index() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic["I"]["Can"]["Get"]["Indexes"]["All"]["Day"]["Like"]["It"]["Aint"]["No"]["Thang"]; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] @@ -67,7 +67,7 @@ public void Set_Index() { dynamic mimic = new DynamicObjects.Mimic(); dynamic result = mimic["I"]["Can"]["Set"]["Indexes"]["All"]["Day"]["Like"]["It"]["Aint"]["No"] = "Thang"; - Assert.That(result, Is.EqualTo("Thang")); + Assert.That((object)result, Is.EqualTo("Thang")); } [Test] @@ -96,31 +96,31 @@ public void Unary() dynamic result; result = !mimic; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = ++mimic; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = --mimic; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic++; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic--; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic += 1; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic -= 1; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic /= 2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic *= 4; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic ^= true; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic |= true; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic &= false; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = mimic %= 5; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] @@ -131,21 +131,21 @@ public void Binary() dynamic result; result = thing1 + thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 - thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 / thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 * thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 | thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 & thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 ^ thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); result = thing1 % thing2; - Assert.That(result, Is.TypeOf()); + Assert.That((object)result, Is.TypeOf()); } [Test] diff --git a/Tests/PrivateTest.cs b/Tests/PrivateTest.cs index 099b0b3..e0c2b6a 100644 --- a/Tests/PrivateTest.cs +++ b/Tests/PrivateTest.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; using Microsoft.CSharp.RuntimeBinder; using NUnit.Framework; @@ -17,21 +17,21 @@ public class PrivateTest : AssertionHelper public void TestInvokePrivateMethod() { var tTest = new TestWithPrivateMethod(); - Assert.That(Dynamic.InvokeMember(tTest, "Test"), Is.EqualTo(3)); + Assert.That((object)Dynamic.InvokeMember(tTest, "Test"), Is.EqualTo(3)); } [Test] public void TestInvokePrivateMethodAcrossAssemblyBoundries() { var tTest = new PublicType(); - Assert.That(Dynamic.InvokeMember(tTest, "PrivateMethod", 3), Is.True); + Assert.That((object)Dynamic.InvokeMember(tTest, "PrivateMethod", 3), Is.True); } [Test] public void TestInvokeInternalTypeMethodAcrossAssemblyBoundries() { var tTest = PublicType.InternalInstance; - Assert.That(Dynamic.InvokeMember(tTest, "InternalMethod", 3), Is.True); + Assert.That((object)Dynamic.InvokeMember(tTest, "InternalMethod", 3), Is.True); } [Test] diff --git a/Tests/Program.cs b/Tests/Program.cs new file mode 100644 index 0000000..088306b --- /dev/null +++ b/Tests/Program.cs @@ -0,0 +1,12 @@ +namespace Dynamitey.Tests +{ +#if !NETCOREAPP2_0 + public class Program + { + public static void Main() + { + + } + } +#endif +} \ No newline at end of file diff --git a/Tests/Properties/AssemblyInfo.cs b/Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 89c3139..0000000 --- a/Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Tests")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("212224a8-cb88-4cb5-83af-c982e56e8bd4")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tests/SpeedTest.cs b/Tests/SpeedTest.cs index b6dc822..3552b1d 100644 --- a/Tests/SpeedTest.cs +++ b/Tests/SpeedTest.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Dynamitey.SupportLibrary1; +using Dynamitey.SupportLibrary; using NUnit.Framework; using Microsoft.FSharp.Reflection; diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 407f6ae..6b95c64 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -1,125 +1,32 @@ - - - + - Debug - AnyCPU - {C33F07DB-7ACB-4081-92C2-BB739CB605C0} - Library - Properties - Dynamitey.Tests - Tests - 512 - ..\ - true - v4.5 - false - true - v4.0 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false + netcoreapp2.0;net462 + Exe + false + - - True - ..\packages\FSharp.Core.4.0.0\lib\FSharp.Core.dll - - - False - ..\packages\ImpromptuInterface.6.2.2\lib\net40\ImpromptuInterface.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\IronPython.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\IronPython.Modules.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\IronPython.SQLite.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\IronPython.Wpf.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\Microsoft.Dynamic.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\Microsoft.Scripting.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\Microsoft.Scripting.AspNet.dll - - - ..\packages\IronPython.2.7.3\lib\Net40\Microsoft.Scripting.Metadata.dll - - - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll - - - ..\packages\NUnit.2.6.2\lib\nunit.framework.dll - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + - - + + + + + - - {ce699ab8-4122-4369-baa6-76244a0734e4} - Dynamitey - - - {348152a9-6a9c-4115-b60a-9e08ca72451d} - SupportLibrary1 - + + - - - \ No newline at end of file diff --git a/Tests/TuplerTest.cs b/Tests/TuplerTest.cs index f3b0ce4..5b364fd 100644 --- a/Tests/TuplerTest.cs +++ b/Tests/TuplerTest.cs @@ -58,21 +58,21 @@ public void DynamicTupleSize() { var tup = Tuple.Create(1, 2, 3, 4, 5); - Assert.That(Tupler.Size(tup),Is.EqualTo(5)); + Assert.That((object)Tupler.Size(tup),Is.EqualTo(5)); } [Test] public void DynamicTupleSize8() { var tup = Tuple.Create(1, 2, 3, 4, 5,6,7,8); - Assert.That(Tupler.Size(tup), Is.EqualTo(8)); + Assert.That((object)Tupler.Size(tup), Is.EqualTo(8)); } [Test] public void DynamicTupleSize20() { var tup = Tupler.Create(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); - Assert.That(Tupler.Size(tup), Is.EqualTo(20)); + Assert.That((object)Tupler.Size(tup), Is.EqualTo(20)); } [Test] @@ -80,7 +80,7 @@ public void DynamicTupleToList() { var tup =Tuple.Create(1, 2, 3, 4, 5); var exp=Enumerable.Range(1,5).ToList(); - Assert.That(Tupler.ToList(tup),Is.EqualTo(exp)); + Assert.That((object)Tupler.ToList(tup),Is.EqualTo(exp)); } @@ -89,7 +89,7 @@ public void DynamicTupleToList8() { var tup = Tuple.Create(1, 2, 3, 4, 5, 6, 7, 8); var exp = Enumerable.Range(1, 8).ToList(); - Assert.That(Tupler.ToList(tup), Is.EqualTo(exp)); + Assert.That((object)Tupler.ToList(tup), Is.EqualTo(exp)); } [Test] @@ -97,7 +97,7 @@ public void DynamicTupleToList20() { var tup = Tupler.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); var exp = Enumerable.Range(1, 20).ToList(); - Assert.That(Tupler.ToList(tup), Is.EqualTo(exp)); + Assert.That((object)Tupler.ToList(tup), Is.EqualTo(exp)); } @@ -107,8 +107,8 @@ public void DynamicListToTuple() { var exp = Enumerable.Range(1, 5).ToList(); var tup = exp.ToTuple(); - Assert.That(Tupler.IsTuple(tup), Is.True); - Assert.That(Tupler.ToList(tup), Is.EqualTo(exp)); + Assert.That((object)Tupler.IsTuple(tup), Is.True); + Assert.That((object)Tupler.ToList(tup), Is.EqualTo(exp)); } @@ -117,8 +117,8 @@ public void DynamicListToTuplet8() { var exp = Enumerable.Range(1, 8).ToList(); var tup = exp.ToTuple(); - Assert.That(Tupler.IsTuple(tup), Is.True); - Assert.That(Tupler.ToList(tup), Is.EqualTo(exp)); + Assert.That((object)Tupler.IsTuple(tup), Is.True); + Assert.That((object)Tupler.ToList(tup), Is.EqualTo(exp)); } [Test] @@ -127,8 +127,8 @@ public void DynamicListToTuple20() var exp = Enumerable.Range(1, 20).ToList(); var tup = exp.ToTuple(); - Assert.That(Tupler.IsTuple(tup), Is.True); - Assert.That(Tupler.ToList(tup), Is.EqualTo(exp)); + Assert.That((object)Tupler.IsTuple(tup), Is.True); + Assert.That((object)Tupler.ToList(tup), Is.EqualTo(exp)); } @@ -137,21 +137,21 @@ public void DynamicListToTuple20() public void DynamicTupleIndex() { var tup = Tupler.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); - Assert.That(Tupler.Index(tup,5), Is.EqualTo(6)); + Assert.That((object)Tupler.Index(tup,5), Is.EqualTo(6)); } [Test] public void DynamicTupleIndex7() { var tup = Tupler.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); - Assert.That(Tupler.Index(tup, 7), Is.EqualTo(8)); + Assert.That((object)Tupler.Index(tup, 7), Is.EqualTo(8)); } [Test] public void DynamicTupleIndex19() { var tup = Tupler.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); - Assert.That(Tupler.Index(tup, 19), Is.EqualTo(20)); + Assert.That((object)Tupler.Index(tup, 19), Is.EqualTo(20)); } } } diff --git a/Tests/packages.config b/Tests/packages.config deleted file mode 100644 index 480eef7..0000000 --- a/Tests/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Version.props b/Version.props new file mode 100644 index 0000000..26e3929 --- /dev/null +++ b/Version.props @@ -0,0 +1,5 @@ + + + 2.0.6 + + \ No newline at end of file diff --git a/build.fsx b/build.fsx new file mode 100755 index 0000000..cc81888 --- /dev/null +++ b/build.fsx @@ -0,0 +1,179 @@ +#!/bin/sh +#if bin_sh + # Doing this because arguments can't be used with /usr/bin/env on linux, just mac + exec fsharpi --define:mono_posix --exec $0 $* +#endif +#if FSharp_MakeFile + +(* + * Single File Crossplatform FSharp Makefile Bootstrapper + * Apache licensed - Copyright 2014 Jay Tuley + * v 2.0 https://gist.github.com/jbtule/11181987 + * + * How to use: + * On Windows `fsi --exec build.fsx + * *Note:* if you have trouble first run "%vs120comntools%\vsvars32.bat" or use the "Developer Command Prompt for VS201X" + * or install https://github.com/Iristyle/Posh-VsVars#posh-vsvars + * + * On Mac Or Linux `./build.fsx ` + * *Note:* But if you have trouble then use `sh build.fsx ` + * + *) + +#I "packages/FAKE/tools" +#r "FakeLib.dll" + +open Fake + +let sln = "./Dynamitey.sln" + +let commonBuild target = + let buildMode = getBuildParamOrDefault "configuration" "Release" + let vsuffix = getBuildParamOrDefault "vsuffix" "" + let setParams defaults = + { defaults with + Verbosity = Some(Quiet) + Targets = [target] + Properties = + [ + "Configuration", buildMode + "VersionSuffix", vsuffix + ] + } + build setParams sln + |> DoNothing + +Target "Restore" (fun () -> + trace " --- Restore Packages --- " + + //because nuget doesn't know how to find msbuild15 on linux + let restoreProj = fun args -> + directExec (fun info -> + info.FileName <- "msbuild" + info.Arguments <- "/t:restore " + args) |> ignore + + sln |> restoreProj + +) + +Target "Clean" (fun () -> + trace " --- Cleaning stuff --- " + commonBuild "Clean" +) + +Target "Build" (fun () -> + trace " --- Building the libs --- " + commonBuild "Build" +) + +Target "Test" (fun () -> + trace " --- Test the libs --- " + + let nunit3exe = "./packages/nunit.consolerunner/3.7.0/tools/nunit3-console.exe" + + let buildMode = getBuildParamOrDefault "configuration" "Release" + + let testDir = sprintf "./Tests/bin/%s/net462/" buildMode + + let netExe, netAppVeyor,coreAppVeyor = + if buildServer = AppVeyor then + "nunit3-console","--result=myresults.xml;format=AppVeyor", "--logger=trx;LogFileName=testresults.trx" + else + nunit3exe,"--noresult","" + + + let s1 = + directExec (fun info -> + info.FileName <- netExe + info.Arguments <- sprintf "--labels=All %s --where=\"cat != Performance\" %s" netAppVeyor (testDir + "Tests.exe")) + + + let s2 = + directExec (fun info -> + info.FileName <- "dotnet" + info.Arguments <- sprintf "test Tests/Tests.csproj -f netcoreapp2.0 --no-build --no-restore --filter=TestCategory!=Performance %s --configuration=%s" coreAppVeyor buildMode) + + let appveyor = environVarOrNone "APPVEYOR_JOB_ID" + match appveyor with + | Some(jobid) -> + use webClient = new System.Net.WebClient() + webClient.UploadFile(sprintf "https://ci.appveyor.com/api/testresults/mstest/%s" jobid,"./Tests/TestResults/testresults.trx") |> ignore + | None -> () + + if(not s1 || not s2) then + failwith "Tests failed" + +) + +"Restore" + ==> "Build" + ==> "Test" + +RunTargetOrDefault "Test" + + +#else + +open System +open System.IO +open System.Diagnostics + +(* helper functions *) +#if mono_posix +#r "Mono.Posix.dll" +open Mono.Unix.Native +let applyExecutionPermissionUnix path = + let _,stat = Syscall.lstat(path) + Syscall.chmod(path, FilePermissions.S_IXUSR ||| stat.st_mode) |> ignore +#else +let applyExecutionPermissionUnix path = () +#endif + +let doesNotExist path = + path |> Path.GetFullPath |> File.Exists |> not + +let execAt (workingDir:string) (exePath:string) (args:string seq) = + let processStart (psi:ProcessStartInfo) = + let ps = Process.Start(psi) + ps.WaitForExit () + ps.ExitCode + let fullExePath = exePath |> Path.GetFullPath + applyExecutionPermissionUnix fullExePath + let exitCode = ProcessStartInfo( + fullExePath, + args |> String.concat " ", + WorkingDirectory = (workingDir |> Path.GetFullPath), + UseShellExecute = false) + |> processStart + if exitCode <> 0 then + exit exitCode + () + +let exec = execAt Environment.CurrentDirectory + +let downloadNugetTo path = + let fullPath = path |> Path.GetFullPath; + if doesNotExist fullPath then + printf "Downloading NuGet..." + use webClient = new System.Net.WebClient() + fullPath |> Path.GetDirectoryName |> Directory.CreateDirectory |> ignore + webClient.DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", path |> Path.GetFullPath) + printfn "Done." + +let passedArgs = fsi.CommandLineArgs.[1..] |> Array.toList + +(* execution script customize below *) + +let makeFsx = fsi.CommandLineArgs.[0] + +let nugetExe = ".nuget/NuGet.exe" +let fakeExe = "packages/FAKE/tools/FAKE.exe" + +downloadNugetTo nugetExe + +if doesNotExist fakeExe then + exec nugetExe ["install"; "fake"; "-OutputDirectory packages"; "-ExcludeVersion"] + +exec fakeExe ([makeFsx; "-d:FSharp_MakeFile"] @ passedArgs) + +#endif \ No newline at end of file diff --git a/dist/build.proj b/dist/build.proj deleted file mode 100644 index 57a8a68..0000000 --- a/dist/build.proj +++ /dev/null @@ -1,17 +0,0 @@ - - - - MySolution - - - - Configuration=Release; - - - Configuration=Release;OutputPath=bin\Release.net40\;IntermediateOutputPath=obj\Release.net40\;UseNet40=true; - - - - - - \ No newline at end of file diff --git a/dist/create-nuget.ps1 b/dist/create-nuget.ps1 deleted file mode 100644 index c36073c..0000000 --- a/dist/create-nuget.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -try{ - - $solname = "Dynamitey" - $testname = "Tests" - $projectname = $solname - $projecttype ="csproj" - - #Build PCL and .NET version from one project using msbuild script - C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe build.proj /p:solname=$solname - - if (!$?){ - throw $error[0].Exception - } - - #Download and configure Nunit test runner - ..\.nuget\nuget.exe install NUnit.Runners -Version 2.6.2 -o ..\packages - Copy-Item nunit-console.exe.config ..\packages\NUnit.Runners.2.6.2\tools\ - - if (!$?){ - throw $error[0].Exception - } - - #Test .net 40 - Echo "Testing Net40" - ..\packages\NUnit.Runners.2.6.2\tools\nunit-console.exe /framework:net-4.0 /noxml /nodots /labels /stoponerror /exclude=Performance ..\$testname\bin\Release.net40\$testname.dll - - if (!$?){ - throw $error[0].Exception - } - - #Test portable - Echo "Testing Portable" - ..\packages\NUnit.Runners.2.6.2\tools\nunit-console.exe /framework:net-4.5 /noxml /nodots /labels /stoponerror /exclude=Performance ..\$testname\bin\Release\$testname.dll - - if (!$?){ - throw $error[0].Exception - } - - -}catch{ - Echo "Build Failed" - exit -} - -#if successful create nuget package -..\.nuget\nuget.exe pack ..\$projectname\$projectname.$projecttype -Properties Configuration=Release -Symbols -Echo "Nuget Success" \ No newline at end of file diff --git a/dist/net40.targets b/dist/net40.targets deleted file mode 100644 index fd59319..0000000 --- a/dist/net40.targets +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dist/nunit-console.exe.config b/dist/nunit-console.exe.config deleted file mode 100644 index 0b42fdb..0000000 --- a/dist/nunit-console.exe.config +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/dist/publish-nuget.bat b/dist/publish-nuget.bat deleted file mode 100644 index 27a371d..0000000 --- a/dist/publish-nuget.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -IF %2.==. GOTO WrongArgs - -set SYMBOLSOURCE="http://nuget.gw.symbolsource.org/Public/NuGet" - -..\.nuget\nuget.exe push %1.nupkg %2 -..\.nuget\nuget.exe push %1.symbols.nupkg %2 -source %SYMBOLSOURCE% - -GOTO:EOF -:WrongArgs -ECHO "publish-nuget " \ No newline at end of file