Skip to content

Commit

Permalink
append SupportedOSPlatformAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 25, 2022
1 parent c199e3a commit 84a6dfc
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// SPDX-FileCopyrightText: 2008 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
#define MICROSOFT_WIN32_REGISTRY
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE || SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMGUARDATTRIBUTE
using System.Runtime.Versioning;
#endif

#if MICROSOFT_WIN32_REGISTRY
using Microsoft.Win32;
#endif

using System;
using System.Collections.Generic;
using System.IO;

namespace Smdn;

#pragma warning disable IDE0040
partial class MimeType {
#pragma warning restore IDE0040
private const string DefaultMimeTypesFile = "/etc/mime.types";

private static bool IsRunningOnWindows => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMGUARDATTRIBUTE
[SupportedOSPlatformGuard("windows")]
#endif
private static bool IsRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

public static MimeType? FindMimeTypeByExtension(string extensionOrPath) => FindMimeTypeByExtension(extensionOrPath, DefaultMimeTypesFile);

Expand Down Expand Up @@ -85,6 +86,9 @@ private static IEnumerable<KeyValuePair<string, string[]>> ReadMimeTypesFileLine
return null;
}

#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
[SupportedOSPlatform("windows")]
#endif
private static MimeType? FindMimeTypeByExtensionWin(string extensionOrPath)
{
var extension = Path.GetExtension(extensionOrPath);
Expand Down Expand Up @@ -148,6 +152,9 @@ private static IEnumerable<string> FindExtensionsByMimeTypeUnix(string mimeType,
}
}

#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
[SupportedOSPlatform("windows")]
#endif
private static IEnumerable<string> FindExtensionsByMimeTypeWin(string mimeType)
{
#if MICROSOFT_WIN32_REGISTRY
Expand Down

0 comments on commit 84a6dfc

Please sign in to comment.