private void ProcessDefines()

in SharpGen/Transform/TransformManager.cs [187:267]


        private void ProcessDefines(ConfigFile file)
        {
            foreach (var defineRule in file.Extension.OfType<DefineExtensionRule>())
            {
                CsTypeBase defineType;

                if (defineRule.Enum != null)
                {
                    var underlyingType = string.IsNullOrWhiteSpace(defineRule.UnderlyingType)
                                                ? null
                                                : TypeRegistry.ImportPrimitiveType(defineRule.UnderlyingType);

                    if (defineRule.SizeOf is {} size && underlyingType == null)
                    {
                        underlyingType = size switch
                        {
                            1 => TypeRegistry.UInt8,
                            2 => TypeRegistry.Int16,
                            4 => TypeRegistry.Int32,
                            _ => null
                        };
                    }

                    var newEnum = new CsEnum(null, defineRule.Enum, underlyingType);

                    defineType = newEnum;
                }
                else if (defineRule.Struct != null)
                {
                    var newStruct = new CsStruct(null, defineRule.Struct);
                    defineType = newStruct;
                    if (defineRule.HasCustomMarshal is { } hasCustomMarshal)
                        newStruct.HasMarshalType = hasCustomMarshal;

                    if (defineRule.IsStaticMarshal is { } isStaticMarshal)
                        newStruct.IsStaticMarshal = isStaticMarshal;

                    if (defineRule.HasCustomNew is { } hasCustomNew)
                        newStruct.HasCustomNew = hasCustomNew;

                    if (defineRule.SizeOf is { } size)
                        newStruct.StructSize = checked((uint) size);

                    if (defineRule.Align is { } align)
                        newStruct.Align = align;

                    if (defineRule.IsNativePrimitive is { } isNativePrimitive)
                        newStruct.IsNativePrimitive = isNativePrimitive;
                }
                else if (defineRule.Interface != null)
                {
                    var iface = new CsInterface(null, defineRule.Interface);

                    if (defineRule.ShadowName is {} shadowName)
                        iface.ShadowName = shadowName;
                    if (defineRule.VtblName is {} vtblName)
                        iface.VtblName = vtblName;

                    if (defineRule.NativeImplementation != null)
                    {
                        iface.NativeImplementation = new CsInterface(null, defineRule.NativeImplementation)
                        {
                            IsDualCallback = true
                        };
                        iface.IsCallback = true;
                        iface.IsDualCallback = true;
                        TypeRegistry.DefineType(iface.NativeImplementation);
                    }

                    defineType = iface;
                }
                else
                {
                    Logger.Error(LoggingCodes.MissingElementInRule, "Invalid rule [{0}]. Requires one of enum, struct, or interface", defineRule);
                    continue;
                }

                // Define this type
                TypeRegistry.DefineType(defineType);
            }
        }