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

Re-enable .NET Standard 1.3 targeting. #112

Merged
merged 1 commit into from
Dec 7, 2017
Merged
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
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## v21.0.1
* Re-enabled **.NET Standard 1.3** targeting.
* Added `Gender` field to `Person`. Deterministic sequences may have changed.
* Added `Randomizer.Bool(weight)` to generate weighted boolean values of true.
* Italian `CodiceFiscale()` extension method added. Extends `Person` and `Finance`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and inspired by [`FluentValidation`](https://github.com/JeremySkinner/FluentVali
```
Install-Package Bogus
```
Minimum Requirements: **.NET Standard 2.0** or **.NET Framework 4.0**.
Minimum Requirements: **.NET Standard 1.3** or **.NET Framework 4.0**.

##### Projects That Use Bogus

Expand Down
11 changes: 9 additions & 2 deletions Source/Bogus/Bogus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PackageReleaseNotes>
<Version>0.0.0-localbuild</Version>
<Authors>Brian Chavez</Authors>
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net40;netstandard1.3;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<CodeAnalysisRuleSet>Default.ruleset</CodeAnalysisRuleSet>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -30,7 +30,10 @@
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);STANDARD</DefineConstants>
<DefineConstants>$(DefineConstants);STANDARD;STANDARD20</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);STANDARD;STANDARD13</DefineConstants>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="data\*.locale.bson" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
Expand All @@ -42,4 +45,8 @@
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
<PackageReference Include="System.Globalization.Extensions" Version="4.3.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/Bogus/Bson/Bson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private string DecodeCString()
break;
ms.WriteByte(buf);
}
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Position);
return Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Position);
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ private void EncodeDocument(MemoryStream ms, BObject obj)

var bw = new BinaryWriter(ms);
bw.Write((Int32)(dms.Position + 4 + 1));
bw.Write(dms.GetBuffer(), 0, (int)dms.Position);
bw.Write(dms.ToArray(), 0, (int)dms.Position);
bw.Write((byte)0);
}

Expand Down
5 changes: 3 additions & 2 deletions Source/Bogus/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using Bogus.Bson;
using Bogus.Platform;

namespace Bogus
{
Expand All @@ -24,7 +25,7 @@ public static class Database
/// </summary>
public static string[] GetAllLocales()
{
var asm = typeof(Database).Assembly;
var asm = typeof(Database).GetAssembly();

return asm.GetManifestResourceNames()
.Where(name => name.EndsWith(".locale.bson"))
Expand All @@ -46,7 +47,7 @@ private static ConcurrentDictionary<string, BObject> Initialize()

internal static BObject InitLocale(string locale)
{
var asm = typeof(Database).Assembly;
var asm = typeof(Database).GetAssembly();
var resourceName = $"Bogus.data.{locale}.locale.bson";

using( var s = asm.GetManifestResourceStream(resourceName) )
Expand Down
1 change: 1 addition & 0 deletions Source/Bogus/Extensions/ExtensionsForString.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Globalization;
using System.Text;

Expand Down
27 changes: 19 additions & 8 deletions Source/Bogus/Platform/ExtensionsForType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.IO;
using System.Reflection;

namespace Bogus.Platform
Expand All @@ -7,21 +8,31 @@ internal static class ExtensionsForType
{
public static T GetCustomAttributeX<T>(this Type type) where T : Attribute
{
#if STANDARD
#if STANDARD20
return type.GetCustomAttribute<T>();
#elif STANDARD13
return type.GetTypeInfo().GetCustomAttribute<T>();
#else
return Attribute.GetCustomAttribute(type, typeof(T)) as T;
#endif
}
}

internal class EnumValueAttribute : Attribute
{
public string Value { get; }
public static bool IsEnum(this Type type)
{
#if STANDARD13
return type.GetTypeInfo().IsEnum;
#else
return type.IsEnum;
#endif
}

public EnumValueAttribute(string value)
public static Assembly GetAssembly(this Type type)
{
this.Value = value;
#if STANDARD13
return type.GetTypeInfo().Assembly;
#else
return type.Assembly;
#endif
}
}
}
3 changes: 2 additions & 1 deletion Source/Bogus/Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using Bogus.Bson;
using Bogus.DataSets;
using Bogus.Platform;

namespace Bogus
{
Expand Down Expand Up @@ -474,7 +475,7 @@ public string ClampString(string str, int? min = null, int? max = null)
public T Enum<T>(params T[] exclude) where T : struct
{
var e = typeof(T);
if( !e.IsEnum )
if( !e.IsEnum() )
throw new ArgumentException("When calling Enum<T>() with no parameters T must be an enum.");

var selection = System.Enum.GetNames(e);
Expand Down