这是什么语法在C#是什么意思?
我可能没有它正确的,但我看到这样的事情上面一个WebMethod:
I may not have it correct, but I saw something like this above a WebMethod:
[return:(XmlElement("Class2"),IsNullable = false)]
public Class2 MEthod1()
{
}
我看到一个VB版第一,我用一个转换器将其转换为C#。我从来没有见过它。这是一个VB 6 ASMX文件。
I saw a vb version first and I used a converter to convert it to c#. I have never seen it before. It's in a vb 6 asmx file.
这是一个属性的目标,而且它的使用在你的榜样,以消除歧义的使用来自其他元素的返回值:
It's an attribute target, and it's being used in your example to disambiguate usage on the return value from other elements:
// default: applies to method
[SomeAttr]
int Method1() { return 0; }
// applies to method
[method: SomeAttr]
int Method2() { return 0; }
// applies to return value
[return: SomeAttr]
int Method3() { return 0; }
在创建属性,你可以指定哪些语言元素的属性可以应用到。这表示在下面的例子中
When creating attributes you can specify which language elements an attribute can be applied to. This is illustrated in the example below.
有关可用目标的列表,在这里看到:
http://msdn.microsoft.com/en-us/library/system .attributetargets.aspx
For a list of available targets see here:
http://msdn.microsoft.com/en-us/library/system.attributetargets.aspx
namespace AttTargsCS
{
// This attribute is only valid on a class.
[AttributeUsage(AttributeTargets.Class)]
public class ClassTargetAttribute : Attribute {
}
// This attribute is only valid on a method.
[AttributeUsage(AttributeTargets.Method)]
public class MethodTargetAttribute : Attribute {
}
// This attribute is only valid on a constructor.
[AttributeUsage(AttributeTargets.Constructor)]
public class ConstructorTargetAttribute : Attribute {
}
// This attribute is only valid on a field.
[AttributeUsage(AttributeTargets.Field)]
public class FieldTargetAttribute : Attribute {
}
// This attribute is valid on a class or a method.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method)]
public class ClassMethodTargetAttribute : Attribute {
}
// This attribute is valid on any target.
[AttributeUsage(AttributeTargets.All)]
public class AllTargetsAttribute : Attribute {
}
[ClassTarget]
[ClassMethodTarget]
[AllTargets]
public class TestClassAttribute {
[ConstructorTarget]
[AllTargets]
TestClassAttribute() {
}
[MethodTarget]
[ClassMethodTarget]
[AllTargets]
public void Method1() {
}
[FieldTarget]
[AllTargets]
public int myInt;
static void Main(string[] args) {
}
}
}