Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework): target netstandard2.0 and net8.0 #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Diwen.Xbrl/ArgumentNullException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if NETSTANDARD2_0

using System.Runtime.CompilerServices;

namespace Diwen.Compat;

/// <summary>
/// Polyfill for the ArgumentNullException factory method from net6.0+
/// </summary>
public static class ArgumentNullException
{
/// <summary>Throws an <see cref="T:System.ArgumentNullException" /> if <paramref name="argument" /> is <see langword="null" />.</summary>
/// <param name="argument">The reference type argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument" /> corresponds.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="argument" /> is <see langword="null" />.</exception>
public static void ThrowIfNull(object argument, [CallerArgumentExpression("argument")] string paramName = null)
{
if (argument is null)
{
throw new System.ArgumentNullException(paramName);
}
}
}
#endif
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Csv/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using Diwen.Xbrl.Csv.Taxonomy;
using Diwen.Xbrl.Extensions;
using Diwen.Xbrl.Xml;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
public partial class Report
Expand Down
11 changes: 10 additions & 1 deletion Diwen.Xbrl/Diwen.Xbrl.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Version>3.4.1</Version>
</PropertyGroup>

Expand All @@ -21,6 +22,14 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="9.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
</ItemGroup>

<Target Name="Date" BeforeTargets="BeforeBuild">
<WriteLinesToFile File="$(IntermediateOutputPath)gen.cs"
Lines="static partial class Builtin { public static long CompileTime = $([System.DateTime]::UtcNow.Ticks) %3B }"
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Extensions/XmlQualifiedNameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace Diwen.Xbrl.Extensions
{
using System;
using System.Xml;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
public static class XmlQualifiedNameExtensions
Expand Down
2 changes: 1 addition & 1 deletion Diwen.Xbrl/Inline/InlineXbrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void ParseFacts(XDocument document, Report report)
if (!string.IsNullOrWhiteSpace(scale))
{
var power = int.Parse(scale);
var v = decimal.Parse(value.Replace(" ", ""));
var v = decimal.Parse(value.Replace(" ", ""), CultureInfo.InvariantCulture);
var multiplier = (decimal)Math.Pow(10, power);
v *= multiplier;
value = v.ToString();
Expand Down
2 changes: 1 addition & 1 deletion Diwen.Xbrl/Json/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static Xml.Report ToXbrlXml(Report report, Dictionary<string, string> dim
context.Period = period;

var metric = fact.Dimensions["concept"].Split(':').Last();
var unitValue = fact.Dimensions.GetValueOrDefault("unit");
var unitValue = fact.Dimensions.GetValueOrDefault("unit", null);
string unitRef = null;
if (unitValue != null)
{
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/ContextCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Diwen.Xbrl.Xml
using System.Collections.ObjectModel;
using System.Globalization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
public class ContextCollection : KeyedCollection<string, Context>, IEquatable<IList<Context>>
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/ExplicitMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace Diwen.Xbrl.Xml
using System.Xml.Schema;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
[XmlRoot(ElementName = "explicitMember", Namespace = "http://xbrl.org/2006/xbrldi")]
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/Fact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Diwen.Xbrl.Xml
using System.Xml;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
public class Fact : IEquatable<Fact>
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/FilingIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace Diwen.Xbrl.Xml
using System.Diagnostics;
using System.Xml.Schema;
using System.Xml.Serialization;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
[DebuggerDisplay("{Value} : {Filed}")]
Expand Down
5 changes: 4 additions & 1 deletion Diwen.Xbrl/Xml/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace Diwen.Xbrl.Xml
using System.Xml;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
[Serializable]
Expand Down Expand Up @@ -114,7 +117,7 @@ public Entity Entity
[XmlIgnore]
public SchemaReference SchemaReference
{
get => SchemaReferences?.FirstOrDefault(new SchemaReference());
get => SchemaReferences?.FirstOrDefault() ?? new SchemaReference();
set => SchemaReferences = [value];
}

Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/TypedMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Diwen.Xbrl.Xml
using System.Xml.Schema;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
[XmlRoot(ElementName = "typedMember", Namespace = "http://xbrl.org/2006/xbrldi")]
Expand Down
3 changes: 3 additions & 0 deletions Diwen.Xbrl/Xml/TypedMemberCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace Diwen.Xbrl.Xml
using System.Xml;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;
#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
public class TypedMemberCollection : Collection<TypedMember>, IEquatable<IList<TypedMember>>
Expand Down
5 changes: 4 additions & 1 deletion Diwen.Xbrl/Xml/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace Diwen.Xbrl.Xml
using System.Xml.Schema;
using System.Xml.Serialization;
using Diwen.Xbrl.Extensions;

#if NETSTANDARD2_0
using ArgumentNullException = Compat.ArgumentNullException;
#endif

/// <summary/>
[DebuggerDisplay("{Id}")]
[Serializable]
Expand Down