Skip to content

Commit fb515b4

Browse files
nirinchevDmitryLukyanov
authored andcommitted
CSHARP-3218: Annotate the MongoDB.Bson assembly with Preserve attribute as necessary.
1 parent d2a370a commit fb515b4

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Please see our [guidelines](CONTRIBUTING.md) for contributing to the driver.
113113
* Bouke Haarsma https://github.com/Bouke
114114
* James Hadwen [email protected]
115115
* Nuri Halperin https://github.com/nurih
116+
* Nikola Irinchev https://github.com/nirinchev
116117
* Jacob Jewell [email protected]
117118
* Danny Kendrick https://github.com/dkendrick
118119
* Ruslan Khasanbaev https://github.com/flaksirus

src/MongoDB.Bson/PreserveAttribute.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
using System;
17+
using System.ComponentModel;
18+
19+
namespace MongoDB.Bson
20+
{
21+
/// <summary>
22+
/// Prevents the Xamarin managed linker from linking the target.
23+
/// </summary>
24+
[AttributeUsage(AttributeTargets.All)]
25+
[EditorBrowsable(EditorBrowsableState.Never)]
26+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Copied from the doc: https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows#preserving-code")]
27+
public sealed class PreserveAttribute : Attribute
28+
{
29+
/// <summary>
30+
/// When used on a class rather than a property, ensures that all members of this type are preserved.
31+
/// </summary>
32+
public bool AllMembers;
33+
34+
/// <summary>
35+
/// Flags the method as a method to preserve during linking if the container class is pulled in.
36+
/// </summary>
37+
public bool Conditional;
38+
}
39+
}

src/MongoDB.Bson/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
using System;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using MongoDB.Bson;
1920

2021
[assembly: CLSCompliant(true)]
2122
[assembly: ComVisible(false)]
2223

24+
// Prevents the Xamarin static linker from stripping anything from this assembly.
25+
// Required for most of the serialization classes on AOT compiled targets, such
26+
// as Xamarin.iOS/Xamarin.Mac.
27+
[assembly: Preserve(AllMembers = true)]
28+
2329
[assembly: InternalsVisibleTo("MongoDB.Bson.Tests")]

src/MongoDB.Driver.Core/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
using System;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using MongoDB.Bson;
1920

2021
[assembly: CLSCompliant(true)]
2122
[assembly: ComVisible(false)]
2223

24+
// Prevents the Xamarin static linker from stripping anything from this assembly.
25+
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
26+
[assembly: Preserve(AllMembers = true)]
27+
2328
[assembly: InternalsVisibleTo("MongoDB.Driver.Core.FunctionalTests")]
2429
[assembly: InternalsVisibleTo("MongoDB.Driver.Core.TestHelpers")]
2530
[assembly: InternalsVisibleTo("MongoDB.Driver.Core.Tests")]

src/MongoDB.Driver.GridFS/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
using System;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using MongoDB.Bson;
1920

2021
[assembly: CLSCompliant(true)]
2122
[assembly: ComVisible(false)]
2223

24+
// Prevents the Xamarin static linker from stripping anything from this assembly.
25+
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
26+
[assembly: Preserve(AllMembers = true)]
27+
2328
[assembly: InternalsVisibleTo("MongoDB.Driver.GridFS.Tests")]

src/MongoDB.Driver.Legacy/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
using System;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using MongoDB.Bson;
1920

2021
[assembly: CLSCompliant(true)]
2122
[assembly: ComVisible(false)]
2223

24+
// Prevents the Xamarin static linker from stripping anything from this assembly.
25+
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
26+
[assembly: Preserve(AllMembers = true)]
27+
2328
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.TestHelpers")]
2429
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.Tests")]

src/MongoDB.Driver/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
using System;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using MongoDB.Bson;
1920

2021
[assembly: CLSCompliant(true)]
2122
[assembly: ComVisible(false)]
2223

24+
// Prevents the Xamarin static linker from stripping anything from this assembly.
25+
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
26+
[assembly: Preserve(AllMembers = true)]
27+
2328
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy")]
2429
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.TestHelpers")]
2530
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.Tests")]

0 commit comments

Comments
 (0)