diff --git a/Directory.Build.props b/Directory.Build.props index 1bcf8740c..d2012b122 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -20,7 +20,7 @@ - + $(NoWarn);CS0436;OOXML0001 diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackage.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackage.cs index e022f4787..ac8ca68f4 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackage.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackage.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Packaging; @@ -11,7 +12,7 @@ namespace DocumentFormat.OpenXml.Packaging; /// /// An abstraction similar to that allows for pass through implementations /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public interface IPackage { /// diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackagePart.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackagePart.cs index f4aa08a5e..eda3a8f62 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackagePart.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackagePart.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; using System.IO; namespace DocumentFormat.OpenXml.Packaging; @@ -9,7 +10,7 @@ namespace DocumentFormat.OpenXml.Packaging; /// /// An abstraction for that is easier to override. /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public interface IPackagePart { /// diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageProperties.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageProperties.cs index a3a500ee9..25083cfe0 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageProperties.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageProperties.cs @@ -2,13 +2,14 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; namespace DocumentFormat.OpenXml.Packaging; /// /// An abstraction of package properties, similar to . /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public interface IPackageProperties { /// diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageRelationship.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageRelationship.cs index 140fd902f..b6e3dfd0a 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageRelationship.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/IPackageRelationship.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; using System.IO.Packaging; namespace DocumentFormat.OpenXml.Packaging; @@ -9,7 +10,7 @@ namespace DocumentFormat.OpenXml.Packaging; /// /// An interface that defines the relationship between a source and a target part. Similar to but allows full overriding. /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public interface IPackageRelationship { /// diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/IRelationshipCollection.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/IRelationshipCollection.cs index a1f0acac4..35a38ed90 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/IRelationshipCollection.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/IRelationshipCollection.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO.Packaging; namespace DocumentFormat.OpenXml.Packaging; @@ -10,7 +11,7 @@ namespace DocumentFormat.OpenXml.Packaging; /// /// A collection of relationships for a of . /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public interface IRelationshipCollection : IEnumerable { /// diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/PackageExtensions.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/PackageExtensions.cs index c5b1438bf..e77388bd1 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/PackageExtensions.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/PackageExtensions.cs @@ -4,13 +4,14 @@ using DocumentFormat.OpenXml.Features; using DocumentFormat.OpenXml.Packaging; using System; +using System.Diagnostics.CodeAnalysis; namespace DocumentFormat.OpenXml.Experimental; /// /// Extensions to retrieve package details. /// -[Obsolete(ExperimentalApis.PackageApis.Message, DiagnosticId = ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] +[Experimental(ExperimentalApis.PackageApis.DiagnosticId, UrlFormat = ExperimentalApis.UrlFormat)] public static class PackageExtensions { /// diff --git a/src/common/FrameworkShims.targets b/src/common/FrameworkShims.targets index a69b97ced..f846188a7 100644 --- a/src/common/FrameworkShims.targets +++ b/src/common/FrameworkShims.targets @@ -8,6 +8,7 @@ + diff --git a/src/common/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs b/src/common/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs new file mode 100644 index 000000000..0e37b513c --- /dev/null +++ b/src/common/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +// Copied from https://github.com/dotnet/runtime/blob/4001e074ee648506d64277729a7cce089a4996e2/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs +// to enable downlevel usage. +#if !NET8_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Indicates that an API is experimental and it may change in the future. +/// +/// +/// This attribute allows call sites to be flagged with a diagnostic that indicates that an experimental +/// feature is used. Authors can use this attribute to ship preview features in their assemblies. +/// +[AttributeUsage( + AttributeTargets.Assembly | + AttributeTargets.Module | + AttributeTargets.Class | + AttributeTargets.Struct | + AttributeTargets.Enum | + AttributeTargets.Constructor | + AttributeTargets.Method | + AttributeTargets.Property | + AttributeTargets.Field | + AttributeTargets.Event | + AttributeTargets.Interface | + AttributeTargets.Delegate, Inherited = false)] +internal sealed class ExperimentalAttribute : Attribute +{ + /// + /// Initializes a new instance of the class, specifying the ID that the compiler will use + /// when reporting a use of the API the attribute applies to. + /// + /// The ID that the compiler will use when reporting a use of the API the attribute applies to. + public ExperimentalAttribute(string diagnosticId) + { + DiagnosticId = diagnosticId; + } + + /// + /// Gets the ID that the compiler will use when reporting a use of the API the attribute applies to. + /// + /// The unique diagnostic ID. + /// + /// The diagnostic ID is shown in build output for warnings and errors. + /// This property represents the unique ID that can be used to suppress the warnings or errors, if needed. + /// + public string DiagnosticId { get; } + + /// + /// Gets or sets the URL for corresponding documentation. + /// The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID. + /// + /// The format string that represents a URL to corresponding documentation. + /// An example format string is https://contoso.com/obsoletion-warnings/{0}. + public string? UrlFormat { get; set; } +} +#endif