Visual Studio 2010 でアプリケーションをプログラミングしていますが、C# を使用してライブラリを参照に追加したいので、使用中のライブラリとビジネス クラスのファイルに呼び出しを追加します。
public void addreference()
{
//needed code
}
public addInvocation()
{
//write in the file of business class
}
マウスを使用して参照を選択するようなものですが、C#を使用してそれを実行したいのですが、 どうすればよいですか?
重要な解決策 解決策 を使用しようとしましたが、問題が見つかりました。ライブラリのクラスを正常にインスタンス化しましたが、それらのメソッドを使用できません
最初に Interface1 というインターフェイスを作成し、次に Classe1 というクラスを作成してから、.dll を生成しました。
コード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public interface Interface1
{
int add();
int sub();
}
public class Class1 : Interface1
{
Class1()
{
}
#region Interface1 Members
public int add()
{
return 10;
}
public int sub()
{
return -10;
}
#endregion
}
}
class1 コードをインスタンス化するために関連付けられた
string relative = "ClassLibrary1.dll";
string absolute = Path.GetFullPath(relative);
Assembly assembly = Assembly.LoadFile(absolute);
System.Type assemblytype = assembly.GetType("ClassLibrary1.Class1");
object a = assembly.CreateInstance("ClassLibrary1.Class1", false, BindingFlags.CreateInstance, null,null,null, null);
今、私はメソッドを追加したいのですが、どうすればそれを行うことができますか