public static void GenerateMember(this CSharpSources gen,
                                          Class @class, Action <Class> generate, bool isVoid = false)
        {
            if (@class != null && @class.IsDependent)
            {
                foreach (var parameter in @class.TemplateParameters)
                {
                    gen.WriteLine($"var __{parameter.Name} = typeof({parameter.Name});");
                }

                foreach (var specialization in @class.Specializations.Where(s => !s.Ignore))
                {
                    WriteTemplateSpecializationCheck(gen, @class, specialization);
                    gen.WriteStartBraceIndent();
                    generate(specialization);
                    if (isVoid)
                    {
                        gen.WriteLine("return;");
                    }
                    gen.WriteCloseBraceIndent();
                }
                ThrowException(gen, @class);
            }
            else
            {
                generate(@class);
            }
        }
示例#2
0
        public static void GenerateField(this CSharpSources gen, Class @class,
                                         Field field, Action <Field, Class, QualifiedType> generate, bool isVoid)
        {
            if (@class.IsDependent)
            {
                if (@class.Fields.Any(f => f.Type.IsDependent))
                {
                    foreach (var parameter in @class.TemplateParameters)
                    {
                        gen.WriteLine($"var __{parameter.Name} = typeof({parameter.Name});");
                    }

                    foreach (var specialization in @class.Specializations.Where(s => s.IsGenerated))
                    {
                        WriteTemplateSpecializationCheck(gen, @class, specialization);
                        gen.WriteStartBraceIndent();
                        var specializedField = specialization.Fields.First(
                            f => f.OriginalName == field.OriginalName);
                        generate(specializedField, specialization, field.QualifiedType);
                        if (isVoid)
                        {
                            gen.WriteLine("return;");
                        }
                        gen.WriteCloseBraceIndent();
                    }
                    ThrowException(gen, @class);
                }
                else
                {
                    var specialization   = @class.Specializations[0];
                    var specializedField = specialization.Fields.First(
                        f => f.OriginalName == field.OriginalName);
                    generate(specializedField, specialization, field.QualifiedType);
                }
            }
            else
            {
                generate(field, @class.IsDependent ? @class.Specializations[0] : @class,
                         field.QualifiedType);
            }
        }