Я пробовал вызывать метод расширения, определенный в статическом классе из Main(), он работал. Теперь я хочу использовать это в своем приложении, чтобы сделать это, мне нужно сделать метод расширения как статический метод (потому что у меня нет статических классов, определенных в моем приложении) и вызывайте его из Main().вызовите метод не расширения, определенный внутри нестатического класса из Main() C#
Вот что я пытаюсь:
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(). Как сделать вызов определенного метода внутри кода? Пожалуйста, помогите мне.
Спасибо.
Get.CopyTo (...? –