Perhaps you might have defined WCF message contracts lately, and you want to be explicit about the encryption level you require for your message parts. I am taking the example of a message contract, but really my point is applicable to any element to which you wish to apply the EncryptionLevel enumeration.
In C#:
[MessageHeader(Name = "Environment", MustUnderstand = true
#if !DEBUG
, ProtectionLevel = ProtectionLevel.Sign
#endif
)]
public String Environment
{
get { return _environment; }
set { _environment = value; }
}
In VB.NET:
#If CONFIG = “Debug”
<MessageHeader(Name:=”Environment”, MustUnderstand:=True)> _
Public Property Environment() As String
#Else
<MessageHeader(Name:=”Environment”, MustUnderstand:=True, ProtectionLevel:=ProtectionLevel.Sign)> _
Public Property Environment() As String
#End If
Get
Return _environment
End Get
Set(ByVal Value As String)
_environment = Value
End Set
End Property
As you can see, there are some key differences in how attributes are specified using conditional compilation:
- In C#, I can toggle parts of the same attribute on and off. In VB.NET, I must repeat the entire attibute (no parts allowed by the compiler).
- Because of line continuation constraints in VB.NET, the line following the line being continued must be included inside the conditional compilation block.
- Using VB.NET in Visual Studio (2005 or 2008), it is not clear which part of the conditional compilation is “active” based on the selected configuration. In C#, the inactive block is grayed out.
Keep in mind these “consequences” as you proceed with WCF attributes in the language you write with.