【发布时间】:2016-08-27 14:37:45
【问题描述】:
我正在尝试扩展“字符串”类。 到目前为止,我已经在声明的字符串对象上创建了扩展函数。
String s = new String();
s = s.Encrypt();
但我想为类本身创建一个扩展函数。
在这种情况下,类似于:String s = String.GetConfig("Test");
到目前为止我尝试了什么:
using System;
using System.Runtime.CompilerServices;
namespace Extensions.String
{
public static class StringExtensions
{
// Error
public string DecryptConfiguration
{
get
{
return "5";
}
}
// Can't find this
public static string GetConfig(string configKey);
// Works, but not what I would like to accomplish
public static string Encrypt(this string thisString);
}
}
任何帮助将不胜感激。 提前谢谢!
【问题讨论】:
-
你不能那样做。
标签: c# string extension-methods