public static void Main()
var labelOne = new LabelOne()
var labelTwo = new LabelTwo()
var printer = new PrintService();
printer.PrintLabel<ILabelTwo>(labelTwo);
public class PrintService {
public void PrintLabel<T>(T obj) {
if (obj as ILabelOne is not null) {
PrintLabelOne(obj as ILabelOne);
} else if (obj as ILabelTwo is not null) {
PrintLabelTwo(obj as ILabelTwo);
Console.WriteLine("Unknown");
private void PrintLabelOne(ILabelOne obj) {
Console.WriteLine($"Let's go print Label One with product name {obj.ProductName}");
private void PrintLabelTwo(ILabelTwo obj) {
Console.WriteLine($"Let's go print Label Two with product name {obj.ProductName}");
public interface IBaseLabel {
public string PrinterName { get; init; }
public interface ILabelOne : IBaseLabel {
public string ProductName { get; init; }
public interface ILabelTwo : IBaseLabel {
public string ProductName { get; init; }
struct LabelOne : ILabelOne
public string PrinterName { get; init; }
public string ProductName { get; init; }
struct LabelTwo : ILabelTwo
public string ProductName { get; init; }
public string PrinterName { get; init; }