현재 버전


class Program
{
    static void Main(string[] args)
    {
        var x = new ConcreteClass();

        string js = JsonConvert.SerializeObject(x);


        var test = JsonConvert.DeserializeObject<ConcreteClass>(js);

        var type = typeof(ConcreteClass);

        var method = type.GetMethod("Print", BindingFlags.NonPublic | BindingFlags.Instance);

        method.Invoke(test, new[] { "Hello World" });
    }
}

public abstract class AbstractClalss
{
    protected void Print(string text)
    {
        Console.WriteLine(text);
    }
}

public class ConcreteClass : AbstractClalss
{

}



수정 이력

2020-07-10 17:08:58 에 아래 내용에서 변경 됨 #1


class Program
{
    static void Main(string[] args)
    {
        var x = new ConcreteClass();

        string js = JsonConvert.SerializeObject(x);


        var test = JsonConvert.DeserializeObject<ConcreteClass>(js);

        var type = typeof(ConcreteClass);

        var method = type.GetMethod("Print", BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance);

        method.Invoke(test, new[] { "Hello World" });
    }
}

public abstract class AbstractClalss
{
    protected void Print(string text)
    {
        Console.WriteLine(text);
    }
}

public class ConcreteClass : AbstractClalss
{

}