Skip to content

Commit 9e567e2

Browse files
CSHARP-2592: Add .NET Standard 2.0 support.
1 parent 8850a9b commit 9e567e2

30 files changed

+395
-25
lines changed

build.cake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ var gitVersion = GitVersion();
1515
var solutionDirectory = MakeAbsolute(Directory("./"));
1616
var artifactsDirectory = solutionDirectory.Combine("artifacts");
1717
var artifactsBinDirectory = artifactsDirectory.Combine("bin");
18-
var artifactsBinNet452Directory = artifactsBinDirectory.Combine("net452");
19-
var artifactsBinNetStandard15Directory = artifactsBinDirectory.Combine("netstandard1.5");
2018
var artifactsDocsDirectory = artifactsDirectory.Combine("docs");
2119
var artifactsDocsApiDocsDirectory = artifactsDocsDirectory.Combine("ApiDocs-" + gitVersion.LegacySemVer);
2220
var artifactsDocsRefDocsDirectory = artifactsDocsDirectory.Combine("RefDocs-" + gitVersion.LegacySemVer);
@@ -75,7 +73,7 @@ Task("BuildArtifacts")
7573
.IsDependentOn("Build")
7674
.Does(() =>
7775
{
78-
foreach (var targetFramework in new[] { "net452", "netstandard1.5" })
76+
foreach (var targetFramework in new[] { "net452", "netstandard1.5", "netstandard2.0" })
7977
{
8078
var toDirectory = artifactsBinDirectory.Combine(targetFramework);
8179
CleanDirectory(toDirectory);

src/MongoDB.Bson/MongoDB.Bson.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.5;net452</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
55
<LangVersion>7.3</LangVersion>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<WarningsAsErrors />

src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
#if NET452 || NETSTANDARD2_0
1819
using System.ComponentModel;
20+
#endif
1921
using System.Linq;
2022
using System.Reflection;
2123
using MongoDB.Bson.IO;
@@ -155,7 +157,7 @@ public TClass DeserializeClass(BsonDeserializationContext context)
155157

156158
Dictionary<string, object> values = null;
157159
var document = default(TClass);
158-
#if NET452
160+
#if NET452 || NETSTANDARD2_0
159161
ISupportInitialize supportsInitialization = null;
160162
#endif
161163
if (_classMap.HasCreatorMaps)
@@ -168,7 +170,7 @@ public TClass DeserializeClass(BsonDeserializationContext context)
168170
// for mutable classes we deserialize the values directly into the result object
169171
document = (TClass)_classMap.CreateInstance();
170172

171-
#if NET452
173+
#if NET452 || NETSTANDARD2_0
172174
supportsInitialization = document as ISupportInitialize;
173175
if (supportsInitialization != null)
174176
{
@@ -319,7 +321,7 @@ public TClass DeserializeClass(BsonDeserializationContext context)
319321

320322
if (document != null)
321323
{
322-
#if NET452
324+
#if NET452 || NETSTANDARD2_0
323325
if (supportsInitialization != null)
324326
{
325327
supportsInitialization.EndInit();
@@ -471,7 +473,7 @@ private TClass CreateInstanceUsingCreator(Dictionary<string, object> values)
471473
var creatorMap = ChooseBestCreator(values);
472474
var document = creatorMap.CreateInstance(values); // removes values consumed
473475

474-
#if NET452
476+
#if NET452 || NETSTANDARD2_0
475477
var supportsInitialization = document as ISupportInitialize;
476478
if (supportsInitialization != null)
477479
{
@@ -491,7 +493,7 @@ private TClass CreateInstanceUsingCreator(Dictionary<string, object> values)
491493
}
492494
}
493495

494-
#if NET452
496+
#if NET452 || NETSTANDARD2_0
495497
if (supportsInitialization != null)
496498
{
497499
supportsInitialization.EndInit();

src/MongoDB.Bson/TargetFramework.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
namespace MongoDB.Bson
17+
{
18+
internal static class TargetFramework
19+
{
20+
public static string Moniker =>
21+
#if NET452
22+
"net452";
23+
#elif NETSTANDARD1_5
24+
"netstandard15";
25+
#elif NETSTANDARD2_0
26+
"netstandard20";
27+
#endif
28+
}
29+
}

src/MongoDB.Driver.Core/MongoDB.Driver.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.5;net452</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
55
<LangVersion>7.3</LangVersion>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<WarningsAsErrors />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
namespace MongoDB.Driver.Core
17+
{
18+
internal static class TargetFramework
19+
{
20+
public static string Moniker =>
21+
#if NET452
22+
"net452";
23+
#elif NETSTANDARD1_5
24+
"netstandard15";
25+
#elif NETSTANDARD2_0
26+
"netstandard20";
27+
#endif
28+
}
29+
}

src/MongoDB.Driver.GridFS/MongoDB.Driver.GridFS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.5;net452</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
55
<LangVersion>7.3</LangVersion>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<WarningsAsErrors />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
namespace MongoDB.Driver.GridFS
17+
{
18+
internal static class TargetFramework
19+
{
20+
public static string Moniker =>
21+
#if NET452
22+
"net452";
23+
#elif NETSTANDARD1_5
24+
"netstandard15";
25+
#elif NETSTANDARD2_0
26+
"netstandard20";
27+
#endif
28+
}
29+
}

src/MongoDB.Driver.Legacy/MongoDB.Driver.Legacy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.5;net452</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
55
<LangVersion>7.3</LangVersion>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<WarningsAsErrors />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
namespace MongoDB.Driver.Legacy
17+
{
18+
internal static class TargetFramework
19+
{
20+
public static string Moniker =>
21+
#if NET452
22+
"net452";
23+
#elif NETSTANDARD1_5
24+
"netstandard15";
25+
#elif NETSTANDARD2_0
26+
"netstandard20";
27+
#endif
28+
}
29+
}

0 commit comments

Comments
 (0)