Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributors: Code Generators #1120

Closed
paulushub opened this issue Jan 2, 2024 · 1 comment
Closed

Contributors: Code Generators #1120

paulushub opened this issue Jan 2, 2024 · 1 comment

Comments

@paulushub
Copy link
Contributor

paulushub commented Jan 2, 2024

Description

  • Svg_Model.cs
    The generators are mainly used to create the parts of partial classes. Interestingly, the file Svg_Model.cs is also generated, and I could not understand what is there to be generated in this file.
  • Framework differences
    I was not expecting differences between the generated outputs for the various supported Frameworks. However, comparing the outputs. there are slight differences

Svg_Model.cs

Question: Please can anyone explain the need to generate this file and its contents?

// <auto-generated />
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;

namespace Svg
{
    [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    public sealed class ElementFactoryAttribute : Attribute
    {
    }

    internal enum DescriptorType
    {
        Property,
        Event
    }

    internal interface ISvgPropertyDescriptor
    {
        DescriptorType DescriptorType { get; }
        string AttributeName { get; }
        string AttributeNamespace { get; }
        TypeConverter Converter { get; }
        Type Type { get; }
        object GetValue(object component);
        void SetValue(object component, ITypeDescriptorContext context, CultureInfo culture, object value);
    }

    internal class SvgPropertyDescriptor<T, TU> : ISvgPropertyDescriptor
    {
        public DescriptorType DescriptorType { get; }
        public string AttributeName { get; }
        public string AttributeNamespace { get; }
        public TypeConverter Converter { get; }
        public Type Type { get; } = typeof(TU);
        private Func<T, TU> Getter { get; }
        private Action<T, TU> Setter { get; }

        public SvgPropertyDescriptor(DescriptorType descriptorType, string attributeName, string attributeNamespace, TypeConverter converter, Func<T, TU> getter, Action<T, TU> setter)
        {
            DescriptorType = descriptorType;
            AttributeName = attributeName;
            AttributeNamespace = attributeNamespace;
            Converter = converter;
            Getter = getter;
            Setter = setter;
        }

        public object GetValue(object component)
        {
            return (object)Getter((T)component);
        }

        public void SetValue(object component, ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (Converter != null)
            {
                Setter((T)component, (TU)Converter.ConvertFrom(context, culture, value));
            }
        }
    }
}

Framework differences

Simply, the following converters are not used for the .NET 6.0, .NET Core 3.1 and .NET Standard 2.1 but are used by the .NET Framework 4.6.2 and .NET Standard 2.0.

  • System.ComponentModel.Int32Converter
  • System.ComponentModel.BooleanConverter

Sample codes are given below, please check the generation of the codes for

  • targetX
  • targetY
  • preserveAlpha

Question: These are set to null in the generated codes for .NET 6.0, .NET Core 3.1 . Any reason for these?

Svg_FilterEffects_SvgConvolveMatrix_Properties.cs - For .NET 6.0, .NET Core 3.1, .NET Standard 2.1

    public partial class SvgConvolveMatrix
    {
        internal override string AttributeName => "feConvolveMatrix";

        internal override List<Type> ClassNames => SvgConvolveMatrixClassNames;

        internal override Dictionary<string, ISvgPropertyDescriptor> Properties => SvgConvolveMatrixProperties;

        internal static List<Type> SvgConvolveMatrixClassNames = new List<Type>() { typeof(Svg.FilterEffects.SvgConvolveMatrix) };

        internal static Dictionary<string, ISvgPropertyDescriptor> SvgConvolveMatrixProperties = new Dictionary<string, ISvgPropertyDescriptor>()
        {
            ["order"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "order", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.Order, (t, v) => t.Order = v),
            ["kernelMatrix"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "kernelMatrix", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.KernelMatrix, (t, v) => t.KernelMatrix = v),
            ["divisor"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Single>(DescriptorType.Property, "divisor", "http://www.w3.org/2000/svg", new System.ComponentModel.SingleConverter(), (t) => t.Divisor, (t, v) => t.Divisor = v),
            ["bias"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Single>(DescriptorType.Property, "bias", "http://www.w3.org/2000/svg", new System.ComponentModel.SingleConverter(), (t) => t.Bias, (t, v) => t.Bias = v),
            ["targetX"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Int32>(DescriptorType.Property, "targetX", "http://www.w3.org/2000/svg", null, (t) => t.TargetX, (t, v) => t.TargetX = v),
            ["targetY"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Int32>(DescriptorType.Property, "targetY", "http://www.w3.org/2000/svg", null, (t) => t.TargetY, (t, v) => t.TargetY = v),
            ["edgeMode"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.FilterEffects.SvgEdgeMode>(DescriptorType.Property, "edgeMode", "http://www.w3.org/2000/svg", new Svg.SvgEdgeModeConverter(), (t) => t.EdgeMode, (t, v) => t.EdgeMode = v),
            ["kernelUnitLength"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "kernelUnitLength", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.KernelUnitLength, (t, v) => t.KernelUnitLength = v),
            ["preserveAlpha"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Boolean>(DescriptorType.Property, "preserveAlpha", "http://www.w3.org/2000/svg", null, (t) => t.PreserveAlpha, (t, v) => t.PreserveAlpha = v),
        };

}

Svg_FilterEffects_SvgConvolveMatrix_Properties.cs - For .NET Framework 4.6.2, .NET Standard 2.0

    public partial class SvgConvolveMatrix
    {
        internal override string AttributeName => "feConvolveMatrix";

        internal override List<Type> ClassNames => SvgConvolveMatrixClassNames;

        internal override Dictionary<string, ISvgPropertyDescriptor> Properties => SvgConvolveMatrixProperties;

        internal static List<Type> SvgConvolveMatrixClassNames = new List<Type>() { typeof(Svg.FilterEffects.SvgConvolveMatrix) };

        internal static Dictionary<string, ISvgPropertyDescriptor> SvgConvolveMatrixProperties = new Dictionary<string, ISvgPropertyDescriptor>()
        {
            ["order"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "order", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.Order, (t, v) => t.Order = v),
            ["kernelMatrix"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "kernelMatrix", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.KernelMatrix, (t, v) => t.KernelMatrix = v),
            ["divisor"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Single>(DescriptorType.Property, "divisor", "http://www.w3.org/2000/svg", new System.ComponentModel.SingleConverter(), (t) => t.Divisor, (t, v) => t.Divisor = v),
            ["bias"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Single>(DescriptorType.Property, "bias", "http://www.w3.org/2000/svg", new System.ComponentModel.SingleConverter(), (t) => t.Bias, (t, v) => t.Bias = v),
            ["targetX"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Int32>(DescriptorType.Property, "targetX", "http://www.w3.org/2000/svg", new System.ComponentModel.Int32Converter(), (t) => t.TargetX, (t, v) => t.TargetX = v),
            ["targetY"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Int32>(DescriptorType.Property, "targetY", "http://www.w3.org/2000/svg", new System.ComponentModel.Int32Converter(), (t) => t.TargetY, (t, v) => t.TargetY = v),
            ["edgeMode"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.FilterEffects.SvgEdgeMode>(DescriptorType.Property, "edgeMode", "http://www.w3.org/2000/svg", new Svg.SvgEdgeModeConverter(), (t) => t.EdgeMode, (t, v) => t.EdgeMode = v),
            ["kernelUnitLength"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, Svg.SvgNumberCollection>(DescriptorType.Property, "kernelUnitLength", "http://www.w3.org/2000/svg", new Svg.SvgNumberCollectionConverter(), (t) => t.KernelUnitLength, (t, v) => t.KernelUnitLength = v),
            ["preserveAlpha"] = new SvgPropertyDescriptor<Svg.FilterEffects.SvgConvolveMatrix, System.Boolean>(DescriptorType.Property, "preserveAlpha", "http://www.w3.org/2000/svg", new System.ComponentModel.BooleanConverter(), (t) => t.PreserveAlpha, (t, v) => t.PreserveAlpha = v),
        };

}
@paulushub paulushub self-assigned this Jan 2, 2024
@paulushub paulushub changed the title Contributors: Generators - Svg_Model.cs Contributors: Code Generators Jan 2, 2024
@paulushub
Copy link
Contributor Author

@svg-net svg-net locked and limited conversation to collaborators Jan 16, 2024
@paulushub paulushub converted this issue into discussion #1127 Jan 16, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant