我的课程ClassName
定义了一个运算符:
public static explicit operator ClassName(Guid value)
{
return new ClassName(value);
}
这允许以这种方式“投射”:
var guids = new[] { Guid.NewGuid, Guid.NewGuid() };
var classes = guids.Select(g => (ClassName)g).ToArray();
如果我有类似
的方法public static ClassName Convert(Guid value)
{
return new ClassName(value);
}
我可以使用方法组:
var guids = new[] { Guid.NewGuid, Guid.NewGuid() };
var classes = guids.Select(ClassName.Convert).ToArray();
是否还有一种方法可以只为显式运算符传递方法组?
我对语法正确的幼稚实验失败了:
guids.Select(ClassName) // no (obviously)
guids.Select(ClassName.ClassName) // no (obviously)
guids.Select((ClassName)) // no (obviously)
guids.Select(ClassName.op_explicit) // no (obviously)