我想创建一个只能为 Serializable 类运行的扩展。有没有这样的代码:
using System;
namespace ConsoleApplication2
{
[Serializable]
public class Ser
{
}
public class NonSer
{
}
public static class Extension
{
static public T f_DeepClone<T>(this T obj)
where T : (SerializableAttribute)
{
return (T) obj;
}
}
public class Program
{
static void Main(string[] args)
{
Ser mc = new Ser();
mc.f_DeepClone<Ser>();
NonSer mc1 = new NonSer();
mc.f_DeepClone<NonSer>();
}
}
}