C#C
C#3y ago
3 replies
Gustavo Barros

❔ What is the difference between public static and public static virtual in a interface?

This is a interface for dynamic plugins loaded from a
AssemblyLoadContext
.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace JJIntegration.PluginContracts;

public interface IScheduleTask
{
    /// more code above...

    /// <summary>
    /// Name of the task that will appear to the user
    /// </summary>
    string TaskName { get; }



    /// <summary>
    /// Add the dependencies from this ScheduleTask to the IServiceCollection of the application
    /// </summary>


    // My friends, what is the difference here if I add a virtual keyword? This method is meant to be optionally overriden.
    public static IServiceCollection AddServices(IServiceCollection services, IConfiguration configuration)
    {
        return services;
    }

    /// more code below...
}


What is the difference between
public static virtual
and
public static
in a interface? When I use
public static virtual
, the method cannot be loaded by reflection.
Was this page helpful?