1

我正在使用 Formflow 生成必要的问题,以便从用户那里获取所有数据。由于我支持多种语言,我不能只使用属性。所以我阅读了它并注意到 RView 可用于生成资源文件。但是,由于我已经对资源文件进行了拆分和排序,因此我正在尝试重用它们。

使用 FieldReflector,我可以很容易地做到这一点

form.Field(new FieldReflector<HolidayPlanningFlowForm>(nameof(StartDate),true)
           .SetType(typeof(string))
           .SetFieldDescription(Resources.HolidayResources.Planning_FlowStartDate_Describe)
           .SetPrompt(new PromptAttribute(Resources.HolidayResources.Planning_FlowStartDate_Prompt)));

很好。但我不知道在哪里为 TemplateUsage.NotUnderstood 或 TemplateUsage.DateTimeHelp 定义模板。在参考文献中,Field 上有一个可用的方法 ReplaceTemplate(),但是这个反射器返回一个 IField,无法弄清楚如何让它工作。

任何人都有最好的选择(我真的不想使用 RView ;))

4

1 回答 1

1

我认为这里的问题是.SetType(typeof(string)) 如果将其更改为typeof(DateTime).ReplaceTemplate ()将按预期运行:

public static IForm<TermFormFlow> BuildForm()
{
    return new FormBuilder<TermFormFlow>()
            .Message("Bla Bla")
            .Field(new FieldReflector<TermFormFlow>(nameof(DateOfBirth), true)
                        .ReplaceTemplate(new TemplateAttribute(TemplateUsage.NotUnderstood, "I do not understand \"{0}\".", "Try again, I don't get \"{0}\"."))
                        .ReplaceTemplate(new TemplateAttribute(TemplateUsage.DateTimeHelp, "This field should be in the format '01/01/2018'", "Please enter a date or time"))
                        .SetType(typeof(DateTime))
                        .SetFieldDescription(Resources.HolidayResources.Planning_FlowStartDate_Describe)
                        .SetPrompt(new PromptAttribute(Resources.HolidayResources.Planning_FlowStartDate_Prompt)))
            .AddRemainingFields()
            .Build();      
}
于 2018-06-01T00:59:00.813 回答