生成.NET DLL包装围绕现有的.NET库 [英] Generate .net dll wrapper around existing .net library

查看:184
本文介绍了生成.NET DLL包装围绕现有的.NET库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ExpensiveAndLargeObfuscatedFoo.dll DLL。 让我们说,它定义了一个名为ExpensiveAndLargeObfuscatedFooSubClass类型。 它被编译为.NET。

是否有任何工具(免费,付费,等等),将产生C#或VB类文件,会做什么,但环绕的所有的这一昂贵的DLL中定义?这样,我可以添加功能,修复bug(即CorpFUBAR将无法修复),添加记录等?

从字面上看,我想要的输出,看起来像这样

 命名空间easytoread {
    公共类SubClass中{
        私人ExpensiveAndLargeObfuscatedFoo.SubClass _originalSubClass;
        公共SubClass中(){
            this._originalSubClass =新ExpensiveAndLargeObfuscatedFoo.SubClass();
        }
        公共字符串StupidBuggyMethod(字符串参数1,INT参数2){
            返回_originalSubClass.StupidBuggyMethod(参数1,参数2);
        }
    }
}
 

它必须处理自定义返回类型,以及元

 命名空间easytoread {
    公共类SubFooClass {
        私人ExpensiveAndLargeObfuscatedFoo.SubFooClass _originalSubFooClass;
        公共SubFooClass(){
            this._originalSubFooClass =新ExpensiveAndLargeObfuscatedFoo.SubFooClass();
        }
        私人SubFooClass(ExpensiveAndLargeObfuscatedFoo.SubFooClass原稿){
            this._originalSubFooClass =原稿;
        }
        公共SubFooClass StupidBuggyMethod(字符串参数1,INT参数2){
            返回新SubFooClass(_originalSubFooClass.StupidBuggyMethod(参数1,参数2));
        }
    }
}
 

等等等等,每一个定义的类。

基本上,穷人芒动态代理? (耶,城堡项目是真棒!)

我们也想重新命名我们的一些包装类,但该工具并不需要这么做。

不重命名,我们就能够替换旧组件我们新生成的一个,改变using语句,并继续像什么都没有发生(除错误是固定!)

这只是需要检查dll和做code一代。生成的code甚至可以是VB.NET,或I​​ronPython的或任何CLR。

这是一个大滑坡,我不开心,我在这里结束了,但是这似乎是一段路要走。我看着城堡项目,但除非我错了,不会的,原因有二:1)我不能重命名任何东西(不问); 2)所有的组件的方法声明为虚,甚至重写。即使他们,有数百种我不得不手动覆盖,这听起来好玩不。

解决方案

这似乎是最好的答案是没有这样的工具。所以,我会采取刺在写我自己后来作为下班时间的项目。如果我得到一些有益的工作,我会Github上,并更新在这里。

更新 的Visual Studio 2012正版正货似乎是有前途的。 http://msdn.microsoft.com/ EN-US /库/ TFS / hh549175(V = vs.110)的.aspx - 我们已经移动了,但我可能会尝试创建一个假的,然后在未来

I have a dll named ExpensiveAndLargeObfuscatedFoo.dll. Lets says it defines a type named ExpensiveAndLargeObfuscatedFooSubClass. It's been compiled for .NET.

Are there any tools (free, paid, whatever) that will generate c# or vb class files that will do nothing but wrap around everything defined in this expensive dll? That way I can add functionality, fix bugs (that CorpFUBAR won't fix), add logging, etc?

Literally, I want output that looks like this

namespace easytoread {
    public class SubClass {
        private ExpensiveAndLargeObfuscatedFoo.SubClass _originalSubClass;
        public SubClass() {
            this._originalSubClass = new ExpensiveAndLargeObfuscatedFoo.SubClass ();
        }
        public string StupidBuggyMethod(string param1,int param2) {
            return _originalSubClass.StupidBuggyMethod(param1, param2);
        }
    }
}

It would have to handle custom return types as well as primitives

namespace easytoread {
    public class SubFooClass {
        private ExpensiveAndLargeObfuscatedFoo.SubFooClass _originalSubFooClass;
        public SubFooClass() {
            this._originalSubFooClass= new ExpensiveAndLargeObfuscatedFoo.SubFooClass ();
        }
        private SubFooClass(ExpensiveAndLargeObfuscatedFoo.SubFooClass orig) {
            this._originalSubFooClass = orig;
        }
        public SubFooClass StupidBuggyMethod(string param1,int param2) {
            return new SubFooClass(_originalSubFooClass.StupidBuggyMethod(param1, param2));
        }
    }
}

And so on and so forth for every single defined class.

Basically, poor mans dynamic proxy? (yay, Castle Project is awesome!)

We'd also like to rename some of our wrapper classes, but the tool doesn't need to do that.

Without renaming, we'd be able to replace the old assembly with our new generated one, change using statements and continue on like nothing happened (except the bugs were fixed!)

It just needs to examine the dll and do code generation. the generated code can even be VB.NET, or ironpython, or anything CLR.

This is a slippery slope and I'm not happy that I ended up here, but this seems to be the way to go. I looked at the Castle Project, but unless I'm mistaken that won't work for two reasons: 1) I can't rename anything (don't ask), 2) none of the assemblies methods are declared virtual or even overridable. Even if they were, there's hundreds of types I'd have to override manually, which doesn't sound fun.

解决方案

It seems the best answer is "There is no such tool". So, I'll be taking a stab at writing my own later as an off-hours project. If I ever get something useful working I'll github it and update here.

UPDATE Visual Studio 2012 Fakes seem to be promising. http://msdn.microsoft.com/en-us/library/tfs/hh549175(v=vs.110).aspx - we've moved on but I might try creating a fake and then dropping it in as a replacement dll sometime in the future

这篇关于生成.NET DLL包装围绕现有的.NET库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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