Main() から静的クラス配下に定義された Extension メソッドを呼び出してみたところ、うまくいきました。これをアプリケーションで使用したいのですが、そのためには、Extension メソッドを静的メソッドとして作成し (アプリケーションで静的クラスが定義されていないため)、Main() から呼び出す必要があります。
ここで私がしようとしていること:
public class Get
{
public static void CopyTo(Stream input, Stream output) //Method
{
byte[] buffer = new byte[32768];
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write (buffer, 0, read);
}
}
public static void Main ()
{
////I' m just mentioning a small part of my code
////Please ignore about the variables(url, baseURL,authenticatestr...) those are not declared here, they have been declared at some other part in the code
/////Here in the main method I have a call to the above method
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
request = (HttpWebRequest)WebRequest.Create (baseURL + uri);
request.Headers.Add ("Authn", authenticateStr);
request.Accept = "";
request.Method = "GET";
webResponse = (HttpWebResponse)request.GetResponse();
using (MemoryStream ms = new MemoryStream())
using (FileStream outfile = new FileStream("1" , FileMode.Create)) {
webResponse.GetResponseStream().CopyTo(ms);///Here I need to call my method
outfile.Write(ms.GetBuffer(), 0, (int)ms.Length);
}
しかし、これはまだ .NetFramework CopyTo() メソッドを呼び出そうとしています。コード内で定義されたメソッドを呼び出すにはどうすればよいですか? 私を助けてください。
ありがとうございました。