using System.Collections.Generic;
public static class Extensions
public static string Run(this ChildA model)
public static string Run(this Parent model)
public static string Run1(this Parent model)
public static string Run2(this Parent model)
return ((ChildA)model).Run();
public static string Run3(this Parent model)
if (model.GetType().BaseType == typeof(Parent))
dynamic changedObj = Convert.ChangeType(model, model.GetType());
public static string Run4(this Parent model)
if (model.GetType().BaseType == typeof(Parent))
var method = typeof(Extensions).GetMethod("Cast");
var generic = method.MakeGenericMethod(new[] { model.GetType() });
return "Not working yet";
public static T Cast<T>(this object input)
public class ChildA : Parent { };
public class ChildB : Parent { };
public static void Main()
var commands = new List<Parent>() { new ChildA(), new ChildB(), new Parent() };
Console.WriteLine(string.Join(", ", commands.Select(c => c.Run())));