SomeClass someObject = new SomeClass();
SomeDelegate someDelegate = someObject.SomeNonStaticMethod;
Console.WriteLine(someDelegate.Target == someObject);
someObject.SomeMethod();
someDelegate.Target.SomeMethod(); // а вот так почему-то нельзя
using System;
namespace SomeNonStatic
{
class Program
{
delegate void someDelegate();
static void Main(string[] args)
{
var so = new SomeClass();
someDelegate sd = so.SomeNonStaticMethod;
Console.WriteLine($"someDelegate.Target == someObject => {sd.Target == so}");
(sd.Target as SomeClass).SomeMethod(); // а вот так почему-то нельзя
}
}
internal class SomeClass
{
internal void SomeNonStaticMethod() => Console.WriteLine("it's SomeNonStaticMethod");
internal void SomeMethod() => Console.WriteLine("it's SomeMethod");
}
}
using System;
namespace SomeNonStatic
{
class Program
{
delegate void someDelegate();
static void Main(string[] args)
{
var so = new SomeClass();
someDelegate sd = so.SomeNonStaticMethod;
Console.WriteLine($"someDelegate.Target == someObject => {sd.Target == so}");
if(sd.Target.GetType() is SomeClass)
(sd.Target as SomeClass).SomeMethod(); // а вот так почему-то нельзя
}
}
internal class SomeClass
{
internal void SomeNonStaticMethod() => Console.WriteLine("it's SomeNonStaticMethod");
internal void SomeMethod() => Console.WriteLine("it's SomeMethod");
}
}