Multi-Platform Package Manager for Stable Diffusion
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
708 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Avalonia.Helpers;
public static class ViewModelSerializer
{
public static Dictionary<string, Type> GetDerivedTypes(Type baseType)
{
return GetJsonDerivedTypeAttributes(baseType).ToDictionary(x => x.typeDiscriminator, x => x.subType);
}
public static IEnumerable<(Type subType, string typeDiscriminator)> GetJsonDerivedTypeAttributes(Type type)
{
return type.GetCustomAttributes<JsonDerivedTypeAttribute>()
.Select(x => (x.DerivedType, x.TypeDiscriminator as string ?? x.DerivedType.Name));
}
}