将 TextBox 文本转换为类型
我想创建一个与工作流变量网格中现有的文本框控件类似的文本框控件。
例如,如果我输入一个字符串,我必须写这样的内容:“str” 例如,如果我输入一个整数值,我会直接写 1...。
我该如何做到这一点,以便我的控件的输出成为一个对象,如果我输入一个数字,那么输出将是整数类型,或者如果我输入一个日期时间,输出将是一个日期时间。
我应该手动解析它还是有一个我可以使用的现有东西。
I want to create a textbox control similar to the one existing in Workflow variables grid.
for exemple if i'm typing a string i must write something like that: "str"
if i'm typing an integer value i write directly 1... for example.
how can i do it so the output of my control be an object, if i enter a number so the output will be of type integer, or if i enter a date time the output will be a DateTime.
Should i have to parse it manually or there is an existing thing that i can use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是在谈论 ExpressionTextBox 控件吗?它事先不知道类型,您仍然必须设置其 ExpressionType 属性,以便它验证其输入。
您想让控件自动识别它是什么类型的输入吗?然后我还建议使用正则表达式,但我认为即使对于最简单的用户定义类型,它也可能变得有点复杂。然后您必须解释这些类型的语法应该如何,这有点违背您首先创建此控件的原因。
附言。我没有答案建议,所以我会把它写成评论,但我没有足够的代表。
Are you talking about the ExpressionTextBox control? It doesn't know the type beforehand, you still have to set its ExpressionType property, for it to validate its input.
Do you want the control to automatically recognize what type of input it is? Then I would also suggest using regular expressions, but I think it might become a bit complex for even the simplest user defined types. Then you would have to explain how the syntax should be for those types, and that's kinda working against why you're making this control in the first place.
PS. I don't have a suggestion for an answer, so I would have written this as a comment instead, but I don't have enough rep.
我会使用 正则表达式(正则表达式)。
使用正则表达式,您可以检查字符串是否由数字组成,格式是否类似于日期或您想要检查的任何内容。
I would use Regular Expression (Regex).
With regex you can check if a String consists of Numbers, is formatted like a Date or whatever you want to check.