是否有向现有 VB.NET 方法添加方面的简单方法? [英] Is there a simple means of adding an aspect to an existing VB.NET method?

查看:14
本文介绍了是否有向现有 VB.NET 方法添加方面的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 VB.NET 有许多面向方面的框架.为了将一个方面添加到几个方法中,将整个框架拉入游戏有点繁重.VB.NET 是否提供了一种简单的方法(通过某种元编程/反射)将方面分层到类/对象中的现有方法上?

I know there are numerous aspect-oriented frameworks for VB.NET. It's a little heavy to pull an entire framework into play in order to add an aspect to a couple methods. Does VB.NET offer a simple means (via some sort of metaprogramming/reflection) in which to layer an aspect over an existing method in a class/object?

基本上,目标是拦截方法的传入消息以调用它并添加副作用或操纵请求,就像在标准 AOP 中通常所做的那样.

Basically, the goal is intercept a method's incoming message to invoke it and add side effects or to manipulate the request, just as one would normally do in standard AOP.

是否有将方面直接集成到语言中的计划?

Are there any plans to integrate aspects directly into the language?

推荐答案

在这种情况下,多态不是一种选择吗?我想您会发现,在某种 AOP 框架之外,在 VB 中无法更改现有类的功能.您可以继承和覆盖基成员,也可以使用扩展方法向现有类添加其他功能,但无法更改现有类中的现有功能.

Is polymorphism not an option in this case? I think you'll find that, outside of an AOP framework of some kind, there is no way in VB to change the functionality of an existing class. You can inherit and override base members, or you can use extension methods to add additional functionality to an existing class, but there's no way to alter existing functionality in an existing class.

可以创建一个模仿另一个现有库的新库,并诱使现有代码认为您的新库是原始库,但除非绝对必要,否则这是一个坏主意.您可能只需要以标准的 OOP 方式重新思考您的设计,而不是从 AOP 的角度思考.

It is possible to create a new library that mimics another existing library and trick existing code into thinking your new library is the original one, but unless absolutely necessary, this is a bad idea. Chances you just need to rethink your design in a standard OOP way rather than thinking in AOP terms.

这篇关于是否有向现有 VB.NET 方法添加方面的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆