diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3e075 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +src/obj +src/bin diff --git a/build.ps1 b/build.ps1 index 3eb680c..3add261 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,77 +14,14 @@ # $here = Split-Path -Parent $MyInvocation.MyCommand.Path -$source = [string](Get-Content -Raw (Join-Path $here "src/serializer.cs")) +dotnet build --configuration Release $here/src/ -function Invoke-LoadInContext { - param( - [string]$assemblyPath, - [string]$loadContextName - ) - - $loadContext = [System.Runtime.Loader.AssemblyLoadContext]::New($loadContextName, $true) - $assemblies = $loadContext.LoadFromAssemblyPath($assemblyPath) +$destinations = @("netstandard2.1", "net47") - return @{ "yaml"= $assemblies } -} - -function Invoke-LoadInGlobalContext { - param( - [string]$assemblyPath - ) - $assemblies = [Reflection.Assembly]::LoadFrom($assemblyPath) - return @{ "yaml"= $assemblies } -} - - -function Invoke-LoadAssembly { - $libDir = Join-Path $here "lib" - $assemblies = @{ - "core" = Join-Path $libDir "netstandard2.1\YamlDotNet.dll"; - "net47" = Join-Path $libDir "net47\YamlDotNet.dll"; - } - - if ($PSVersionTable.Keys -contains "PSEdition") { - if ($PSVersionTable.PSEdition -eq "Core") { - return (Invoke-LoadInContext -assemblyPath $assemblies["core"] -loadContextName "powershellyaml") - } elseif ($PSVersionTable.PSVersion.Major -gt 5.1) { - return (Invoke-LoadInContext -assemblyPath $assemblies["net47"] -loadContextName "powershellyaml") - } else { - return (Invoke-LoadInGlobalContext $assemblies["net47"]) - } - } else { - return (Invoke-LoadInGlobalContext $assemblies["net47"]) - } -} - -$assemblies = Invoke-LoadAssembly -$yamlDotNetAssembly = $assemblies["yaml"] - - -if (!([System.Management.Automation.PSTypeName]'StringQuotingEmitter').Type) { - $referenceList = @($yamlDotNetAssembly.Location,[Text.RegularExpressions.Regex].Assembly.Location, "System.Management.Automation.dll", "System.Collections.dll") - if ($PSVersionTable.PSEdition -eq "Core") { - $referenceList += [IO.Directory]::GetFiles([IO.Path]::Combine($PSHOME, 'ref'), 'netstandard.dll', [IO.SearchOption]::TopDirectoryOnly) - $destinations = @("lib/netstandard2.1") - $referenceList += 'System.Runtime.Numerics.dll' - } else { - $referenceList += 'System.Runtime.dll' - $destinations = @("lib/net47") - $referenceList += 'System.Numerics.dll' - } -} - -$destinations = @("lib/netstandard2.1", "lib/net47") +foreach ($item in $destinations) { + $src = Join-Path $here "src" "bin" "Release" $item "serializer.dll" + $dst = Join-Path $here "lib" $item "StringQuotingEmitter.dll" -foreach ($target in $destinations) { - $targetPath = Join-Path $here $target - $file = Join-Path $targetPath "StringQuotingEmitter.dll" - if (!(Test-Path $file)) { - if ($PSVersionTable.PSEdition -eq "Core") { - Add-Type -TypeDefinition $source -ReferencedAssemblies $referenceList -Language CSharp -CompilerOptions "-nowarn:1701" -OutputAssembly $file - } else { - Add-Type -TypeDefinition $source -ReferencedAssemblies $referenceList -Language CSharp -OutputAssembly $file - } - } + Copy-Item -Force $src $dst } diff --git a/lib/net47/StringQuotingEmitter.dll b/lib/net47/StringQuotingEmitter.dll index 30217fe..837286f 100644 Binary files a/lib/net47/StringQuotingEmitter.dll and b/lib/net47/StringQuotingEmitter.dll differ diff --git a/lib/netstandard2.1/StringQuotingEmitter.dll b/lib/netstandard2.1/StringQuotingEmitter.dll index 899d2f2..c19f15b 100644 Binary files a/lib/netstandard2.1/StringQuotingEmitter.dll and b/lib/netstandard2.1/StringQuotingEmitter.dll differ diff --git a/powershell-yaml.psm1 b/powershell-yaml.psm1 index c033595..218eef1 100644 --- a/powershell-yaml.psm1 +++ b/powershell-yaml.psm1 @@ -331,10 +331,6 @@ function Convert-PSObjectToGenericObject { } $dataType = $data.GetType() - if ($data -isnot [System.Object]) { - return $data -as $dataType - } - if (([System.Collections.Specialized.OrderedDictionary].IsAssignableFrom($dataType))){ return Convert-OrderedHashtableToDictionary $data } elseif (([System.Collections.IDictionary].IsAssignableFrom($dataType))){ @@ -342,7 +338,7 @@ function Convert-PSObjectToGenericObject { } elseif (([System.Collections.IList].IsAssignableFrom($dataType))) { return Convert-ListToGenericList $data } - return $data -as $dataType + return $data } function ConvertFrom-Yaml { diff --git a/src/serializer.csproj b/src/serializer.csproj new file mode 100644 index 0000000..4732e1e --- /dev/null +++ b/src/serializer.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.1;net47 + + + + + + + + +