示例#1
0
        public IMemberComposer CreateStruct(ITypeComposer typeComposer, IComponentProvider provider, Func <GeneratingTypeName, string, INamedTypeSymbol> symbolProvider)
        {
            var components = _componentCollection.Components.Select(x => provider.ProvideComponent(x)).ToList();

            var builder = new CodeSourceFileBuilder(_typeName.Namespace);

            builder.Using("System");

            builder.AttributeHideEditor().AttributeGenerated(typeof(MemberComposerSource).Assembly);
            builder.NestType(_typeName, $"internal readonly struct {_typeName.TypeName} {GetGenericArgs()}", node => {
                // Fields & Field Initialization
                AddComponents(builder, components).NewLine();
                AddComponentInitializers(builder, provider.DiscoveryType, components).NewLine();

                // Construtor
                AddConstructor(builder, provider.DiscoveryType, components).NewLine();
                AddTryConstructor(builder, provider.DiscoveryType, components).NewLine();

                // Entry Point
                builder.Comment("Dependency Member Entry Point");
                builder.AddParsingMethods(new ParsingMethodWithTypeBuilder(_member));

                // Data Condition Methods
                for (int i = 0; i < _conditions.Count; i++)
                {
                    builder.AddFormatterMethods(_conditions[i], _member, i, GetDefaultNames).NewLine();
                }

                // Data Format Method
                builder.AddFormatterFinalMethods(_format, _member, _conditions.Count, GetDefaultNames).NewLine();

                // Data Resolve Method
                builder.Comment("Data Resolver").NewLine();
                for (var i = 0; i < components.Count; i++)
                {
                    builder.AddParsingBody(components[i], _member, _componentCollection.GetMethodNames(i)).NewLine();
                }

                // Nested Throw Helpers
                builder.Comment("Throw Helpers (Avoid inlining throw action)");
                _throwCollection.AddThrowClass(builder);
            });

            return(new MemberComposer(typeComposer, _member, symbolProvider(_typeName, builder.ToString()), GetMethodSignatures(provider)));
        }