InterfaceBaseInvoke.Fody
0.1.3
See the version list below for details.
dotnet add package InterfaceBaseInvoke.Fody --version 0.1.3
NuGet\Install-Package InterfaceBaseInvoke.Fody -Version 0.1.3
<PackageReference Include="InterfaceBaseInvoke.Fody" Version="0.1.3" />
paket add InterfaceBaseInvoke.Fody --version 0.1.3
#r "nuget: InterfaceBaseInvoke.Fody, 0.1.3"
// Install InterfaceBaseInvoke.Fody as a Cake Addin #addin nuget:?package=InterfaceBaseInvoke.Fody&version=0.1.3 // Install InterfaceBaseInvoke.Fody as a Cake Tool #tool nuget:?package=InterfaceBaseInvoke.Fody&version=0.1.3
InterfaceBaseInvoke.Fody
This is an add-in for Fody which contains a workaround for Interface Default Implementation Base Invocation
.
The feature has not been implemented by C# team yet.
The status for it can be seen in https://github.com/dotnet/csharplang/issues/2337
Installation
Include the
Fody
andInterfaceBaseInvoke.Fody
NuGet packages with aPrivateAssets="all"
attribute on their<PackageReference />
items. InstallingFody
explicitly is needed to enable weaving.<PackageReference Include="Fody" Version="..." PrivateAssets="all" /> <PackageReference Include="InterfaceBaseInvoke.Fody" Version="..." PrivateAssets="all" />
If you already have a
FodyWeavers.xml
file in the root directory of your project, add the<InterfaceBaseInvoke />
tag there. This file will be created on the first build if it doesn't exist:<?xml version="1.0" encoding="utf-8" ?> <Weavers> <InterfaceBaseInvoke /> </Weavers>
See Fody usage for general guidelines, and Fody Configuration for additional options.
Usage
Call the extension method Base<T>
to cast an object to one of its interfaces, and then call a method or a property.
Just like:
var result = this.Base<Interface>().Method(1, "test");
var value = this.Base<Interface>().Property
Examples
Unit tests can also serve as examples of API usage. See test cases for valid usage and invalid usage.
Basic example:
public interface IService { int Property => 5; void Method() => Console.WriteLine("Calling..."); } public class Service : IService { // call the implementation of interface's property public int Property => this.Base<IService>().Property + 1; public void Method() { Console.WriteLine("Before call method"); // call the implementation of interface's method this.Base<IService>().Method(); Console.WriteLine("After call method"); } }
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Fody (>= 6.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.