C#中使用唯一的代码添加引用(没有IDE"新增参考和QUOT;函数) [英] C# add a reference using only code (no IDE "Add Reference" functions)
问题描述
我书面方式对程序的插件,我希望把我的一个DLL里的代码,所以我可以自由地共享插件不暴露(放弃)我的代码。
I am writting a plugin for a program, and I want to put my code inside a DLL so I can share the plugin freely without exposing (giving away) my code.
下面是基本的结构,我有机会获得:
Here is the basic structure i have access to :
using System;
public class Plugin
{
public void Initialize()
{
//do stuff here
doWork();
}
}
然后我就引用.cs文件我的代码在与节目吃了这个插件。现在,我已经把几个逻辑在里面,包括主要的arent拴直接到初始化(),只在的doWork()函数的功能,启动整个系统。
Then i just reference the .cs file my code is at and the program "eats" up this Plugin. Now, i have put several logic in there, consisting mostly of functions that arent tied directly to "Initialize()", only on the doWork() function, that starts the whole system.
现在,我希望把我所有的代码一个DLL里面,然后刚刚从里面初始化(),myDll.doWork()(或类似的东西)调用。
Now, I want to put all my code inside a DLL, and then just call from inside Initialize(), myDll.doWork() (or something like that).
PS:这个DLL将OFC是编译的C#库(?难道是所谓的动态组装进口这难道不真的是动态的,因为它会反正编译执行前,右)
PS: This dll would ofc be a compiled C# library (could it be called dynamic assembly import? it wouldnt really be dynamic since it would be compiled pre-execution anyways, right?)
PS2:这样我还可以添加自定义的资源,例如表格,图像和这样的没有太大的困难权
PS2: This way I can also add custom resources like forms, images and such without much difficulty right?
PS3:有一个免费的工具保护代码中的DLL里面呢? (即从beeing轻松地重新设计的保护)
PS3: Is there a free tool for protecting the code inside such DLL? (ie protect from beeing easily re engineered)
感谢=)
推荐答案
找到正是我一直在寻找的,那就是:
Found exactly what I was looking for, here it is:
using System.Reflection;
using System.IO;
try
{
Assembly a = null;
a = Assembly.LoadFrom(Application.StartupPath startupPath + "MyAssembly.dll");
Type classType = a.GetType("MyNamespace.MyClass");
object obj = Activator.CreateInstance(classType);
MethodInfo mi = classType.GetMethod("MyMethod");
mi.Invoke(obj, null);
}
catch (Exception e)
{
AddLog(e.Message);
}
这篇关于C#中使用唯一的代码添加引用(没有IDE"新增参考和QUOT;函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!