Skip to content

Commit

Permalink
CSHARP-3218: Annotate the MongoDB.Bson assembly with Preserve attribu…
Browse files Browse the repository at this point in the history
…te as necessary.
  • Loading branch information
nirinchev authored and DmitryLukyanov committed Oct 15, 2020
1 parent d2a370a commit fb515b4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Please see our [guidelines](CONTRIBUTING.md) for contributing to the driver.
* Bouke Haarsma https://github.com/Bouke
* James Hadwen james.hadwen@sociustec.com
* Nuri Halperin https://github.com/nurih
* Nikola Irinchev https://github.com/nirinchev
* Jacob Jewell jacobjewell@eflexsystems.com
* Danny Kendrick https://github.com/dkendrick
* Ruslan Khasanbaev https://github.com/flaksirus
Expand Down
39 changes: 39 additions & 0 deletions src/MongoDB.Bson/PreserveAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright 2020-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.ComponentModel;

namespace MongoDB.Bson
{
/// <summary>
/// Prevents the Xamarin managed linker from linking the target.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
[EditorBrowsable(EditorBrowsableState.Never)]
[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")]
public sealed class PreserveAttribute : Attribute
{
/// <summary>
/// When used on a class rather than a property, ensures that all members of this type are preserved.
/// </summary>
public bool AllMembers;

/// <summary>
/// Flags the method as a method to preserve during linking if the container class is pulled in.
/// </summary>
public bool Conditional;
}
}
6 changes: 6 additions & 0 deletions src/MongoDB.Bson/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MongoDB.Bson;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

// Prevents the Xamarin static linker from stripping anything from this assembly.
// Required for most of the serialization classes on AOT compiled targets, such
// as Xamarin.iOS/Xamarin.Mac.
[assembly: Preserve(AllMembers = true)]

[assembly: InternalsVisibleTo("MongoDB.Bson.Tests")]
5 changes: 5 additions & 0 deletions src/MongoDB.Driver.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MongoDB.Bson;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

// Prevents the Xamarin static linker from stripping anything from this assembly.
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
[assembly: Preserve(AllMembers = true)]

[assembly: InternalsVisibleTo("MongoDB.Driver.Core.FunctionalTests")]
[assembly: InternalsVisibleTo("MongoDB.Driver.Core.TestHelpers")]
[assembly: InternalsVisibleTo("MongoDB.Driver.Core.Tests")]
Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB.Driver.GridFS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MongoDB.Bson;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

// Prevents the Xamarin static linker from stripping anything from this assembly.
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
[assembly: Preserve(AllMembers = true)]

[assembly: InternalsVisibleTo("MongoDB.Driver.GridFS.Tests")]
5 changes: 5 additions & 0 deletions src/MongoDB.Driver.Legacy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MongoDB.Bson;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

// Prevents the Xamarin static linker from stripping anything from this assembly.
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
[assembly: Preserve(AllMembers = true)]

[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.TestHelpers")]
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.Tests")]
5 changes: 5 additions & 0 deletions src/MongoDB.Driver/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MongoDB.Bson;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

// Prevents the Xamarin static linker from stripping anything from this assembly.
// Required for most of the reflection usage in Xamarin.iOS/Xamarin.Mac.
[assembly: Preserve(AllMembers = true)]

[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy")]
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.TestHelpers")]
[assembly: InternalsVisibleTo("MongoDB.Driver.Legacy.Tests")]
Expand Down

0 comments on commit fb515b4

Please sign in to comment.