比方說,我有一個靜態類,使用下面的擴展方法,它從緩存中檢索文件或從磁盤讀取文件,並將其放入緩存(如果它不存在)+對內容進行一些更改(例如,添加標記或屬性): public static class Foo
{
public static DoSomething(this HtmlHelper helper, string url, List<string> parameters)
擴展方法當然可用於將方法添加到您不屬於的類。 但我想在Visual Studio中練習這個概念,但不確定所需的符號。 例如,我有下面的類 public static class Dog
{
public static void Bark()
{
Console.WriteLine("Woof!");
}
}
假設我並不擁有這個方法(這是我做的,但讓
我有這2類: AbstractTaskDispatcher <?php
declare(strict_types=1);
namespace MyExample;
abstract class AbstractTaskDispatcher
{
public final function getResult(Task $task) : Result
{
我有靜態方法的類: public class CompletelyStatic {
public final static String PARAM = "abc";
public static String doSomethingSpecial() {
return "qqq" + PARAM;
}
}
這些方法在整個代碼everywere使