Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility for netstandard2.1 #13

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SOFTWARE. -->
<DefineConstants>CLIENT</DefineConstants>
<AssemblyName>client</AssemblyName>
<PublishName>communication\client</PublishName>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" Version="4.7.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. -->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<DefineConstants>SERVER</DefineConstants>
<AssemblyName>server</AssemblyName>
<PublishName>communication\server</PublishName>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" Version="4.7.0" />
Expand All @@ -41,4 +43,5 @@ SOFTWARE. -->
</ItemGroup>
<Import Project="..\Sharing\JSSoft.Communication.Services\JSSoft.Communication.Services.projitems" Label="Shared" />
<Import Project="..\Sharing\JSSoft.Communication.ConsoleApp\JSSoft.Communication.ConsoleApp.projitems" Label="Shared" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <copyright file="CancellationTokenSourceExtensions.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET8_0_OR_GREATER
#pragma warning disable

using System.Threading;
using System.Threading.Tasks;

namespace JSSoft.Communication;

internal static class CancellationTokenSourceExtensions
{
public static Task CancelAsync(this CancellationTokenSource @this)
{
return Task.Run(() => @this.Cancel());
}

}

#endif // !NET8_0_OR_GREATER
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// <copyright file="CompilerFeatureRequiredAttribute.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET7_0_OR_GREATER
#pragma warning disable
// https://stackoverflow.com/questions/74447497/is-it-possible-to-use-the-c11-required-modifier-with-net-framework-4-8-and

namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}

public string FeatureName { get; }
public bool IsOptional { get; init; }

public const string RefStructs = nameof(RefStructs);
public const string RequiredMembers = nameof(RequiredMembers);
}

#endif // !NET7_0_OR_GREATER
15 changes: 15 additions & 0 deletions src/JSSoft.Communication/Compatibility/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <copyright file="IsExternalInit.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET5_0_OR_GREATER
#pragma warning disable
using System.ComponentModel;

namespace System.Runtime.CompilerServices;

[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }

#endif // !NET5_0_OR_GREATER
22 changes: 22 additions & 0 deletions src/JSSoft.Communication/Compatibility/ObjectDisposedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="ObjectDisposedException.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET7_0_OR_GREATER
#pragma warning disable
namespace JSSoft.Communication;

internal class ObjectDisposedException(string objectName)
: System.ObjectDisposedException(objectName)
{
public static void ThrowIf(bool condition, object instance)
{
if (condition == true)
{
throw new System.ObjectDisposedException(instance.GetType().Name);
}
}
}

#endif // !NET7_0_OR_GREATER
17 changes: 17 additions & 0 deletions src/JSSoft.Communication/Compatibility/RequiredMemberAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// <copyright file="RequiredMemberAttribute.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET7_0_OR_GREATER
#pragma warning disable
#pragma warning disable MEN002 // Line is too long
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field
| AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute { }


#pragma warning restore MEN002 // Line is too long
#endif // !NET7_0_OR_GREATER
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="SetsRequiredMembersAttribute.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

#if !NET7_0_OR_GREATER
#pragma warning disable
namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute { }

#endif // !NET7_0_OR_GREATER
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
// </copyright>

#if !NET7_0_OR_GREATER
#pragma warning disable
using System;

namespace JSSoft.Communication;

class UnreachableException : SystemException
internal sealed class UnreachableException : SystemException
{
public UnreachableException()
{
Expand All @@ -19,4 +20,4 @@ public UnreachableException(string message)
{
}
}
#endif // !NET6_0_OR_GREATER
#endif // !NET7_0_OR_GREATER
1 change: 1 addition & 0 deletions src/JSSoft.Communication/EndPointUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static bool TryParse(string text, [MaybeNullWhen(false)] out EndPoint end
{
return new($"{iPEndPoint.Address}", iPEndPoint.Port, credentials);
}

throw new NotSupportedException($"'{endPoint}' is not supported.");
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/JSSoft.Communication/Grpc/AdaptorServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ internal sealed class AdaptorServer : IAdaptor
private readonly Timer _timer;
#if NETSTANDARD
private Server? _server;
#pragma warning disable S1450
private AdaptorServerImpl? _adaptor;
#pragma warning restore S1450
#elif NET
private IHost? _host;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/JSSoft.Communication/ServiceInstanceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ private static Type CreateType(
}
}

#if NET7_0_OR_GREATER
return typeBuilder.CreateType();
#else
return typeBuilder.CreateType() ?? throw new InvalidOperationException("type is null.");
#endif
}

private static void CreateInvoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SOFTWARE. -->
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn Condition="'$(_IsPacking)'=='true'">$(NoWarn);NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
Expand Down