public override void Generate(StringBuilder builder, string fullClassName, SimpleTermDefinition definition)
 {
     if (definition.AllParameters.Any())
     {
         CSharpGenerationHelper.GenerateTermDeclaration_Method(builder, this.settings, fullClassName, definition);
     }
     else
     {
         CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, definition, definition.Key, @public: true);
     }
 }
        public override void Generate(StringBuilder builder, string fullClassName, PluralTermDefinition definition)
        {
            var zero = GetTerm(definition, Plurality.Zero);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, zero, '_' + definition.Key + "_Zero");

            var one = GetTerm(definition, Plurality.One);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, one, '_' + definition.Key + "_One");

            var two = GetTerm(definition, Plurality.Two);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, two, '_' + definition.Key + "_Two");

            var few = GetTerm(definition, Plurality.Few);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, few, '_' + definition.Key + "_Few");

            var many = GetTerm(definition, Plurality.Many);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, many, '_' + definition.Key + "_Many");

            var other = GetTerm(definition, Plurality.Other);

            CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, other, '_' + definition.Key + "_Other");

            CSharpGenerationHelper.GenerateXmlDocComments(builder, settings, other);

            builder.AppendLine($@"		public static Term {definition.Key}({string.Join(", ", definition.AllParameters.Select(p => p.Type + ' ' + p.Name))})
		{{
			return new ParameterisedTerm(new DelegatedTerm(""{definition.Key}"", culture =>
			{{
				var plurality = PluralRules.GetPlurality(culture, {definition.PluralParameterName});
				switch (plurality)
				{{
					case Plurality.Zero:
						return _{definition.Key}_Zero;
					case Plurality.One:
						return _{definition.Key}_One;
					case Plurality.Two:
						return _{definition.Key}_Two;
					case Plurality.Few:
						return _{definition.Key}_Few;
					case Plurality.Many:
						return _{definition.Key}_Many;
					case Plurality.Other:
					default:
						return _{definition.Key}_Other;
				}}
			}}), {string.Join(", ", definition.AllParameters.Select(p => p.Name))});
		}}"        );
        }
Ejemplo n.º 3
0
        public override void Generate(StringBuilder builder, string fullClassName, ComplexTermDefinition definition)
        {
            foreach (var complexity in definition.Complexities)
            {
                CSharpGenerationHelper.GenerateTermDeclaration_Property(builder, this.settings, fullClassName, complexity.Value, '_' + definition.Key + '_' + complexity.Key.Replace('.', '_'));
            }

            builder.AppendLine().AppendLine("		/// <summary>");
            foreach (var complexity in definition.Complexities)
            {
                var defaultCopy = complexity.Value.Translations[this.settings.DefaultCulture];
                builder.Append("		/// ").Append(this.settings.DefaultCulture.Name).Append(", ").Append(complexity.Key).Append(": \"").Append(defaultCopy.OriginalValue).AppendLine("\"");
            }
            builder.AppendLine("		/// </summary>");

            builder.AppendLine($@"		public static Term {definition.Key}({string.Join(", ", definition.AllParameters.Select(p => p.Type + ' ' + p.Name))})
		{{
			return new ParameterisedTerm(new DelegatedTerm(""{definition.Key}"", culture =>
			{{
				switch ({definition.ComplexParameter.Name})
				{{"                );


            foreach (var complexity in definition.Complexities)
            {
                builder.AppendLine($@"
					case {complexity.Key}:
						return _{definition.Key}_{complexity.Key.Replace('.', '_')};"                        );
            }
            builder.Append($@"
				}}

				return new EmptyTerm();
			}})"            );

            if (definition.AllParameters.Count > 1)
            {
                builder.Append($", {string.Join(", ", definition.AllParameters.Skip(1).Select(p => p.Name))}");
            }

            builder.AppendLine($@");
		}}"        );
        }