I may not have it correct, but I saw something like this above a WebMethod:
[return:(XmlElement("Class2"),IsNullable = false)]
public Class2 MEthod1()
{
}
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.
Syntax basically refers to the protocols to be followed while writing a program. It is very necessary to follow proper syntax while coding to get the desired set of output. The C basic syntax consists of header files, main function, and program code. This is the most fundamental structure in the C program.
Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors.
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.
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) {
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With