internal class Program
{
private static void Main()
{
var c = new ExeptionCultureNode() {
En_US = "dfdf",
Ru_RU = "sdssd"
};
}
}
interface ICultureNode
{
public string Ru_RU { get; init; }
public string En_US { get; init; }
public string En_CA { get; init; }
}
class ExeptionCultureNode : ICultureNode
{
public string Ru_RU { get; init; }
public string En_US { get; init; }
public string En_CA { get; init; }
}
using System;
public class Program
{
public static void Main()
{
var labelOne = new LabelOne()
{
ProductName = "Test 1"
};
var labelTwo = new LabelTwo()
{
ProductName = "Test 2"
};
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);
} else {
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; }
}