将查询参数转换为枚举 [英] Converting query parameter to enum

查看:50
本文介绍了将查询参数转换为枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来有点像这样的枚举:


私有枚举MyEnum

{

SomeValue = 0 ,

AnotherValue = 1,

ThirdValue = 2

}

我有一个会传入的网址像这样的价值,我想把这个枚举:



http://ABCSite/MyPage.aspx?MyParameter = SomeValue


我想使用Request.QueryString来检索MyParameter

值(等于SomeValue)并将其转换为类型为en />
MyEnum的枚举。有没有一种快速简便的方法,或者我会建立一个选择案例来检查所有可能来的价值

in?
/>

解决方案

Doug,


您可以在Enum类上调用静态Parse方法,传递类型

的Enum以及代表该字段的字符串,然后它应该

将值返回给你。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse .com


" Doug" < dn ****** @ dtgnet.com写信息

新闻:12 ************************ ********** @ 56g2000h sm.googlegroups.com ...


>我有一个看起来像这样的枚举:


私人枚举MyEnum

{

SomeValue = 0,

AnotherValue = 1,

ThirdValue = 2

}


我有一个会传递一个这样的值的网址,我想放入

进入该枚举:

http:/ /ABCSite/MyPage.aspx?MyParameter=SomeValue


我想使用Request.QueryString来检索MyParameter

值(等于SomeValue)并将其转换为

MyEnum类型的枚举。有没有一种快速简便的方法,或者我会建立一个选择案例来检查可能来的所有潜在价值

in?



7月28日,1:52 * pm,Nicholas Paldino [.NET / C#MVP]

< m ... @ spam.guard.caspershouse.comwrote:


Doug,


* *您可以在Enum类上调用静态Parse方法,传递Enum的类型

以及表示该字段的字符串,然后它应该返回

返回对你有价值。


-

* * * * * - Nicholas Paldino [.NET / C#MVP]

* * * * * - m ... @ spam.guard.caspershouse.com


" Doug" < dnlwh ... @ dtgnet.com写信息


新闻:12 *********************** *********** @ 56g2000h sm.googlegroups.com ...


我有一个看起来像这样的枚举:


* * private enum MyEnum

* * {

* * * * SomeValue = 0 ,

* * * * AnotherValue = 1,

* * * * ThirdValue = 2

* *}


我有一个会传递一个这样的值的网址,我想把这个值放在这个枚举中:

http://ABCSite/MyPage.aspx?MyParameter = SomeValue


我想使用Request.QueryString来检索MyParameter

值(等于 SomeValue")和将其转换为

MyEnum类型的枚举。 *是否有一种快速简便的方法,或者我将建立一个选择案例来检查所有可能来的价值

in?隐藏引用的文字 -



- 显示引用的文字 -



我在其中任何一个都没有看到Parse函数只是枚举对象,

我的实际枚举对象或我用我的枚举类型创建的变量

对象。你能给我发一个链接来查看解析函数吗?

enum'的?


Doug,


这是Parse方法的文档:

http://msdn.microsoft.com/en-us/libr...num.parse.aspx


-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com


" Doug" < dn ****** @ dtgnet.com写信息

新闻:1c ************************ ********** @ p25g2000 hsf.googlegroups.com ...

7月28日下午1:52,Nicholas Paldino [.NET / C#MVP]"

< m ... @ spam.guard.caspershouse.comwrote:


Doug,


您可以在Enum类上调用静态Parse方法,传递Enum的类型

以及表示该字段的字符串,然后它将

应该

将值返还给你。


-

- Nicholas Paldino [.NET / C#MVP]

- m ... @ spam.guard.caspershouse.com


" Doug" < dnlwh ... @ dtgnet.com写信息


新闻:12 *********************** *********** @ 56g2000h sm.googlegroups.com ...


我有一个看起来像这样的枚举:


private enum MyEnum

{

SomeValue = 0,

AnotherValue = 1,

ThirdValue = 2

}


我有一个网址将传递一个这样的值,我想将

放入该枚举:

http://ABCSite/MyPage.aspx?MyParameter = SomeValue


我想使用Request.QueryString来检索MyParameter

值(等于SomeValue)并将其转换为典型的枚举e $>
MyEnum。有没有一种快速简便的方法,或者我打算用

构建一个精选案例来检查可能来的所有潜在价值

in? - 隐藏引用文本 -



- 显示引用文本 -



我没有看到任何一个Parse函数枚举对象,

我的实际枚举对象或我用我的枚举类型创建的变量

对象。你能给我发一个链接来查看解析函数吗?

enum'的?


I have an enum that will look kind of like this:

private enum MyEnum
{
SomeValue = 0,
AnotherValue = 1,
ThirdValue = 2
}
I have an url that will pass in a value like this that I want to put
into that enum:

http://ABCSite/MyPage.aspx?MyParameter=SomeValue

I''d like to use the Request.QueryString to retrieve the MyParameter
value (which equals "SomeValue") and convert that to an enum of type
MyEnum. Is there a quick and easy way to do it, or am I going to have
to build a select case to check all potential values that could come
in?

解决方案

Doug,

You can call the static Parse method on the Enum class, passing the type
of the Enum as well as the string representing the field, and then it should
return the value to you.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Doug" <dn******@dtgnet.comwrote in message
news:12**********************************@56g2000h sm.googlegroups.com...

>I have an enum that will look kind of like this:

private enum MyEnum
{
SomeValue = 0,
AnotherValue = 1,
ThirdValue = 2
}
I have an url that will pass in a value like this that I want to put
into that enum:

http://ABCSite/MyPage.aspx?MyParameter=SomeValue

I''d like to use the Request.QueryString to retrieve the MyParameter
value (which equals "SomeValue") and convert that to an enum of type
MyEnum. Is there a quick and easy way to do it, or am I going to have
to build a select case to check all potential values that could come
in?



On Jul 28, 1:52*pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

Doug,

* * You can call the static Parse method on the Enum class, passing the type
of the Enum as well as the string representing the field, and then it should
return the value to you.

--
* * * * * - Nicholas Paldino [.NET/C# MVP]
* * * * * - m...@spam.guard.caspershouse.com

"Doug" <dnlwh...@dtgnet.comwrote in message

news:12**********************************@56g2000h sm.googlegroups.com...

I have an enum that will look kind of like this:

* *private enum MyEnum
* *{
* * * *SomeValue = 0,
* * * *AnotherValue = 1,
* * * *ThirdValue = 2
* *}

I have an url that will pass in a value like this that I want to put
into that enum:

http://ABCSite/MyPage.aspx?MyParameter=SomeValue

I''d like to use the Request.QueryString to retrieve the MyParameter
value (which equals "SomeValue") and convert that to an enum of type
MyEnum. *Is there a quick and easy way to do it, or am I going to have
to build a select case to check all potential values that could come
in?- Hide quoted text -


- Show quoted text -

I am not seeing a Parse function within either just the enum object,
my actual enum object or a variable I create with a type of my enum
object. Can you send me a link to review the Parse function for
enum''s?


Doug,

This is the documentation for the Parse method:

http://msdn.microsoft.com/en-us/libr...num.parse.aspx

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Doug" <dn******@dtgnet.comwrote in message
news:1c**********************************@p25g2000 hsf.googlegroups.com...
On Jul 28, 1:52 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

Doug,

You can call the static Parse method on the Enum class, passing the type
of the Enum as well as the string representing the field, and then it
should
return the value to you.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Doug" <dnlwh...@dtgnet.comwrote in message

news:12**********************************@56g2000h sm.googlegroups.com...

I have an enum that will look kind of like this:

private enum MyEnum
{
SomeValue = 0,
AnotherValue = 1,
ThirdValue = 2
}

I have an url that will pass in a value like this that I want to put
into that enum:

http://ABCSite/MyPage.aspx?MyParameter=SomeValue

I''d like to use the Request.QueryString to retrieve the MyParameter
value (which equals "SomeValue") and convert that to an enum of type
MyEnum. Is there a quick and easy way to do it, or am I going to have
to build a select case to check all potential values that could come
in?- Hide quoted text -


- Show quoted text -

I am not seeing a Parse function within either just the enum object,
my actual enum object or a variable I create with a type of my enum
object. Can you send me a link to review the Parse function for
enum''s?


这篇关于将查询参数转换为枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆