English 中文(简体)
统一申请区——从C#到VB的vert例子
原标题:Unity Application Block - Convert example from C# to VB

I m试图将WPF的起点从C#改为VB.net,除一个地区外,Im实际上做得很好。 使用统一应用区进行依赖性注射。

我有以下C#代码组:

            Type viewModelType = viewModelAssembly.GetType(action.ViewModelTypeName);

            var notificationPolicy = unity.AddNewExtension<Interception>()
                .RegisterType(typeof(BaseViewModel), viewModelType, action.Name)
                .Configure<Interception>()
                .SetDefaultInterceptorFor(viewModelType, new VirtualMethodInterceptor())
                .AddPolicy("NotificationPolicy");

            notificationPolicy.AddMatchingRule(new PropertyMatchingRule("*", PropertyMatchingOption.Set));
            notificationPolicy.AddCallHandler<NotifyPropertyChangedCallHandler>();

I auto-convert to vb.net:

Dim viewModelType As Type = viewModelAssembly.[GetType](action.ViewModelTypeName)

Dim notificationPolicy = unity.AddNewExtension(Of Interception()).RegisterType(GetType(BaseViewModel), viewModelType, action.Name).Configure(Of Interception)().SetDefaultInterceptorFor(viewModelType, New VirtualMethodInterceptor()).AddPolicy("NotificationPolicy")

notificationPolicy.AddMatchingRule(New PropertyMatchingRule("*", PropertyMatchingOption.[Set]))
notificationPolicy.AddCallHandler(Of NotifyPropertyChangedCallHandler)()

单币代码产生错误,即“低限超负荷分辨率不能适用于登记Type,因为取用场是接口类型”,我不知道我如何确定这一点。 我完全是对这一团结的新.,除零碎的MS提议外,我也找不到虚的例子。 任何帮助都将受到高度赞赏。

感谢大家,

瑞 典

EDIT:Per Blam,我添加了外语,但我仍然有同样的错误。

问题回答

我看不出,当它失踪时,如何汇编:

 Dim notificationPolicy = unity.AddNewExtension(Of Interception()) _
.RegisterType(GetType(BaseViewModel), viewModelType, action.Name) _
.Configure(Of Interception)() _
.SetDefaultInterceptorFor(viewModelType, New VirtualMethodInterceptor()) _
.AddPolicy("NotificationPolicy")

这里有:

Add NewExtension(Of Interception()).Register ...

您的VB法典看着ok。 这里可能有两个不同的问题。 首先,你们是否使用团结2.0? 您的vb档案中是否有“Importssoft.Practices. Unity”的顶端? 登记册Type上的大部分超载被定义为接口上的延伸方法,没有这份进口说明,汇编者就拿到了。

第二个问题是:

通知政策:

这里没有任何类型的通知,因此VB必须进行猜测。 否则,我认为,它会猜测反对,而倒退到迟到的束缚。

这里有两种选择。

首先,将“Option Infer On”添加到您的vb档案中。 这种推论转而发生。

如果做不到工作,则修改该法典,宣布该类型。 在本案中:

政策定义

或者最后,你可以把最后两条法典线合并起来,忘记变数。 而是:

unity.AddNewExtension(Of Interception()) _
    .RegisterType(GetType(BaseViewModel), viewMOdelType, action.Name) _
    .Configure(Of Interception)() _
    .SetDefaultInterceptorFor(viewModelType, new VirtualMethodInterceptor()) _
    .AddPolicy("NotificationPolicy") _
        .AddMatchingRule(new PropertyMatchingRule("*", PropertyMatchingOption.[Set])) _
        .AddCallHandler(Of NotifyPropertyChangedCallHandler)()

希望这一帮助。

我利用红十字与红新月异构体来看待不同的语言。 虽然有时它没有产生最佳参考法。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签