开发者

C# to vb.net conversion

I need to convert this code from C# to VB. I'm not sure of the proper syntax.

C#

[XcoWorkerExtension(Optional = new Type[] 开发者_运维知识库{ typeof(Subscribe<OnNewsArrived>) })]
    private readonly XcoPublisher<OnNewsArrived> publisher = new    XcoPublisher<OnNewsArrived>();

This is what I've come up with in VB:

<XcoWorkerExtension([Optional]:=New Type() {GetType(Subscribe(Of OnNewsArrived))})> _
    Private ReadOnly publisher As New XcoPublisher(Of OnNewsArrived)()

The C# version runs fine but when I try to run the VB version I'm getting this exception:

System.IO.FileLoadException was unhandled Message=The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Source=mscorlib

The exception is generated at the first line of this sub:

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;
    }


Sorry for giving a "meta answer".

For small conversions like this, Reflector is a nice tool if you are unsure about syntax and/or results.

Possibilities of use:

  1. Compile in C#, and decompile to VB.Net.
  2. Compile in VB.Net, compare to original


C# to VB Converter

Worked for one of my projects, though I suspect there are a few things that will make it unhappy. And you as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜