SvgProperty.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Xml.Linq;
  2. using PixiEditor.SVG.Units;
  3. namespace PixiEditor.SVG;
  4. public abstract class SvgProperty
  5. {
  6. protected SvgProperty(string svgName)
  7. {
  8. SvgName = svgName;
  9. }
  10. protected SvgProperty(string svgName, string? namespaceName) : this(svgName)
  11. {
  12. NamespaceName = namespaceName;
  13. }
  14. public string? NamespaceName { get; set; }
  15. public string SvgName { get; set; }
  16. public ISvgUnit? Unit { get; set; }
  17. public ISvgUnit? CreateDefaultUnit()
  18. {
  19. var genericType = this.GetType().GetGenericArguments();
  20. if (genericType.Length == 0)
  21. {
  22. return null;
  23. }
  24. ISvgUnit unit = Activator.CreateInstance(genericType[0]) as ISvgUnit;
  25. if (unit == null)
  26. {
  27. throw new InvalidOperationException("Could not create unit");
  28. }
  29. return unit;
  30. }
  31. }
  32. public class SvgProperty<T> : SvgProperty where T : struct, ISvgUnit
  33. {
  34. public new T? Unit
  35. {
  36. get => (T?)base.Unit;
  37. set => base.Unit = value;
  38. }
  39. public SvgProperty(string svgName) : base(svgName)
  40. {
  41. }
  42. public SvgProperty(string svgName, string? namespaceName) : base(svgName, namespaceName)
  43. {
  44. }
  45. }