怎么进行自动匹配
我有一个枚举类型
public enum Operator
{
// 摘要:
// 类似(LIKE '%value%')
Like = 0,
//
// 摘要:
// 左类似(LIKE 'value%')
LLike = 1,
//
// 摘要:
// 右类似(LIKE '%value')
RLike = 2,
//
// 摘要:
// 不类似(NOT LIKE '%value%')
NLike = 3,
//
// 摘要:
// 左不类似(NOT LIKE 'value%')
NLLike = 4,
//
// 摘要:
// 右不类似(NOT LIKE '%value')
NRLike = 5,
//
// 摘要:
// 等于
EQ = 6,
//
// 摘要:
// 不等于
NE = 7,
//
// 摘要:
// 大于
GT = 8,
//
// 摘要:
// 大于等于
GE = 9,
//
// 摘要:
// 小于
LT = 10,
//
// 摘要:
// 小于等于
LE = 11,
现在,我得到了一个字符串 str 假设值是 "EQ" 。我要把这个字符串翻译成枚举里的值(应该是6),然后保存到一个实体变量里。
例如:
Entity.opreator=6
有没有办法直接把字符串转换成枚举值?最好是这样的语句
Entity.opreator=Operator.(str)
[解决办法]
可以通过代码来获取枚举类型的所有item的string的
具体好像是Enum这个类吧
[解决办法]
Entity.opreator= (Operator)Enum.Parse(typeof(Operator),"EQ");
[解决办法]
Enum.Parse
int i = (int)(Operator)Enum.Parse(typeof(Operator), "EQ");
[解决办法]
参考这这个:http://www.knowsky.com/541032.html