我正在使用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;))
答案 0 :(得分: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();
}