using System.Collections.Generic;
public static void Main()
var version = MsdVersion.V2;
var supportedTypes = GetSupportedVehicleTypes(version);
Console.WriteLine("supported types in " + version + ": " + string.Join(", ", supportedTypes));
var serializer = MsdVehicleTypeSerializerFactory.GetSerializer(version);
var serialization = supportedTypes.ToDictionary(t => t, t => serializer.Serialize(t));
foreach (var kvp in serialization)
Console.WriteLine(kvp.Key + ": " + kvp.Value);
private enum MsdVehicleType
[SupportsMsdVersion(MsdVersion.V2)]
[SupportsMsdVersion(MsdVersion.V3)]
[SupportsMsdVersion(MsdVersion.V2)]
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
private class SupportsMsdVersionAttribute : Attribute
public SupportsMsdVersionAttribute(MsdVersion version)
public MsdVersion Version { get; }
private static IEnumerable<MsdVehicleType> GetSupportedVehicleTypes(MsdVersion filter)
return Enum.GetValues<MsdVehicleType>()
.Where(vt => typeof(MsdVehicleType)
.GetMember(vt.ToString()).First()
.GetCustomAttributes(typeof(SupportsMsdVersionAttribute), false)
.Any(a => ((SupportsMsdVersionAttribute)a).Version == filter));
private interface IMsdVehicleTypeSerializer
string Serialize(MsdVehicleType vehicleType);
private class MsdVehicleTypeSerializerV2 : IMsdVehicleTypeSerializer
public string Serialize(MsdVehicleType vehicleType) => vehicleType.ToString() + "_V2";
private class MsdVehicleTypeSerializerV3 : IMsdVehicleTypeSerializer
public string Serialize(MsdVehicleType vehicleType) => vehicleType.ToString() + "_V3";
private class MsdVehicleTypeSerializerFactory
public static IMsdVehicleTypeSerializer GetSerializer(MsdVersion version)
return new MsdVehicleTypeSerializerV2();
return new MsdVehicleTypeSerializerV3();
throw new ArgumentOutOfRangeException(nameof(version), version, $"there is no serializer for {version}");