我需要將此代碼從C#轉換爲VB。我不確定正確的語法。C#到vb.net轉換
C#
[XcoWorkerExtension(Optional = new Type[] { typeof(Subscribe<OnNewsArrived>) })]
private readonly XcoPublisher<OnNewsArrived> publisher = new XcoPublisher<OnNewsArrived>();
這是我想出在VB:
<XcoWorkerExtension([Optional]:=New Type() {GetType(Subscribe(Of OnNewsArrived))})> _
Private ReadOnly publisher As New XcoPublisher(Of OnNewsArrived)()
C#版本運行良好,但是當我嘗試運行VB版本我得到這個例外:
System.IO.FileLoadException未處理 消息=給定的程序集名稱或代碼庫無效。 (從HRESULT異常:0x80131047) 源= mscorlib程序
例外在此子的第一行中產生:
internal XcoWorkerExtensionAttribute Get_worker_extension_attribute(FieldInfo field)
{
object[] fieldAttrs = field.GetCustomAttributes(typeof(XcoWorkerExtensionAttribute), false);
object[] classAttrs = field.FieldType.GetCustomAttributes(typeof(XcoWorkerExtensionAttribute), false);
if (fieldAttrs.Length > 0 && classAttrs.Length == 0)
throw new XcoWorkerException("A field can only be marked with the XcoWorkerExtension attribute when its type is also marked with this attribute");
if (fieldAttrs.Length > 0)
return (XcoWorkerExtensionAttribute)fieldAttrs[0];
if (classAttrs.Length > 0)
return (XcoWorkerExtensionAttribute)classAttrs[0];
return null;
}
好吧,我想我已經消除了synatx作爲錯誤的原因。我使用了反射器,並提出了相同的確切代碼。 – jweaver 2010-07-12 15:22:19