QueryStringConverter 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 클래스는 쿼리 문자열의 매개 변수를 적절한 형식의 개체로 변환합니다. 개체에서 해당 쿼리 문자열 표현으로 매개 변수를 변환할 수도 있습니다.
public ref class QueryStringConverter
public class QueryStringConverter
type QueryStringConverter = class
Public Class QueryStringConverter
- 상속
-
QueryStringConverter
- 파생
예제
다음 코드에서는 클래스를 QueryStringConverter 사용하여 문자열과 32비트 정수 간에 변환하는 방법을 보여 있습니다.
QueryStringConverter converter = new QueryStringConverter();
if (converter.CanConvert(typeof(Int32)))
converter.ConvertStringToValue("123", typeof(Int32));
int value = 321;
string strValue = converter.ConvertValueToString(value, typeof(Int32));
Console.WriteLine("the value = {0}, the string representation of the value = {1}", value, strValue);
Dim converter As New QueryStringConverter()
If (converter.CanConvert(GetType(Int32))) Then
converter.ConvertStringToValue("123", GetType(Int32))
End If
Dim value As Integer = 321
Dim strValue As String = converter.ConvertValueToString(value, GetType(Int32))
Console.WriteLine("the value = {0}, the string representation of the value = {1}", value, strValue)
설명
URL 내의 쿼리 문자열에서 매개 변수를 지정할 수 있습니다. 이 클래스는 문자열에 지정된 매개 변수를 가져와 개체로 변환합니다. 예를 들어 다음 계약이 정의됩니다.
[ServiceContract]
interface Calculator
{
[WebGet(UriTemplate="Add?n1={n1}&n2={n2}")]
[OperationContract]
long Add(long n1, long n2);
}
WCF(Windows Communication Foundation) 서비스는 이 인터페이스를 구현하고 WebHttpBehaviorhttp://localhost:8000/MyCalcService 사용하여 엔드포인트에 노출합니다.
Add HTTP GET을 전송하여 서비스 작업을 호출할 http://localhost:8000/MyCalcService/Add?n1=10&n2=5수 있습니다. 이 QueryStringConverter URL을 수신하고 URL에 지정된 두 매개 변수(n1 및 n2)를 적절한 값을 가진 두 long 개체로 변환합니다.
쿼리 문자열 매개 변수가 서비스 작업의 매개 변수에 매핑되는 방법을 제어하기 위해 클래스 QueryStringConverter 를 파생시킬 수 있습니다.
기본적으로 QueryStringConverter 다음 형식을 지원합니다.
Byte 배열
열거형 데이터
문자열 표현과 형식을 변환할 수 있는
TypeConverterAttribute있는 형식입니다.
생성자
| Name | Description |
|---|---|
| QueryStringConverter() |
QueryStringConverter 클래스의 새 인스턴스를 초기화합니다. |
메서드
| Name | Description |
|---|---|
| CanConvert(Type) |
지정된 형식을 문자열 표현과 변환할 수 있는지 여부를 결정합니다. |
| ConvertStringToValue(String, Type) |
쿼리 문자열 매개 변수를 지정된 형식으로 변환합니다. |
| ConvertValueToString(Object, Type) |
매개 변수를 쿼리 문자열 표현으로 변환합니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |