20
20
using JetBrains . Annotations ;
21
21
using RestSharp . Validation ;
22
22
23
- namespace RestSharp
24
- {
23
+ namespace RestSharp {
25
24
/// <summary>
26
25
/// Parameter container for REST requests
27
26
/// </summary>
28
27
[ Obsolete ( "Use Add[XXX]Parameter methods of IRestRequest instead of instantiating the Parameter class." ) ]
29
- public class Parameter : IEquatable < Parameter >
30
- {
31
- public Parameter ( string name , object value , ParameterType type )
32
- {
28
+ public class Parameter : IEquatable < Parameter > {
29
+ public Parameter ( string name , object ? value , ParameterType type , bool encode = true ) {
33
30
if ( type != ParameterType . RequestBody )
34
31
Ensure . NotEmpty ( name , nameof ( name ) ) ;
35
32
36
- Name = name ;
37
- Value = type != ParameterType . UrlSegment ? value : value ? . ToString ( ) . Replace ( "%2F" , "/" ) . Replace ( "%2f" , "/" ) ;
38
- Type = type ;
33
+ Name = name ;
34
+ Value = type != ParameterType . UrlSegment ? value : value ? . ToString ( ) . Replace ( "%2F" , "/" ) . Replace ( "%2f" , "/" ) ;
35
+ Type = type == ParameterType . QueryStringWithoutEncode ? ParameterType . QueryString : type ;
36
+ Encode = type != ParameterType . QueryStringWithoutEncode && encode ;
39
37
}
40
38
41
- public Parameter ( string name , object value , string contentType , ParameterType type ) : this ( name , value , type ) => ContentType = contentType ;
39
+ public Parameter ( string name , object value , string contentType , ParameterType type , bool encode = true ) : this ( name , value , type , encode )
40
+ => ContentType = contentType ;
42
41
43
42
/// <summary>
44
43
/// Name of the parameter
@@ -65,49 +64,45 @@ public Parameter(string name, object value, ParameterType type)
65
64
/// </summary>
66
65
public string ? ContentType { get ; set ; }
67
66
67
+ internal bool Encode { get ; }
68
+
68
69
/// <summary>
69
70
/// Return a human-readable representation of this parameter
70
71
/// </summary>
71
72
/// <returns>String</returns>
72
73
public override string ToString ( ) => $ "{ Name } ={ Value } ";
73
74
74
- public bool Equals ( Parameter other )
75
- {
75
+ public bool Equals ( Parameter ? other ) {
76
76
if ( ReferenceEquals ( null , other ) ) return false ;
77
77
if ( ReferenceEquals ( this , other ) ) return true ;
78
78
79
- return Name == other . Name
80
- && Equals ( Value , other . Value )
81
- && Type == other . Type
82
- && DataFormat == other . DataFormat
83
- && ContentType == other . ContentType ;
79
+ return Name == other . Name &&
80
+ Equals ( Value , other . Value ) &&
81
+ Type == other . Type &&
82
+ DataFormat == other . DataFormat &&
83
+ ContentType == other . ContentType ;
84
84
}
85
85
86
- public override bool Equals ( object obj )
87
- => ! ReferenceEquals ( null , obj )
88
- && ( ReferenceEquals ( this , obj ) || obj . GetType ( ) == this . GetType ( ) && Equals ( ( Parameter ) obj ) ) ;
86
+ public override bool Equals ( object ? obj )
87
+ => ! ReferenceEquals ( null , obj ) && ( ReferenceEquals ( this , obj ) || obj . GetType ( ) == GetType ( ) && Equals ( ( Parameter ) obj ) ) ;
89
88
90
89
// ReSharper disable NonReadonlyMemberInGetHashCode
91
- public override int GetHashCode ( )
92
- {
93
- unchecked
94
- {
90
+ public override int GetHashCode ( ) {
91
+ unchecked {
95
92
var hashCode = Name != null ? Name . GetHashCode ( ) : 0 ;
96
93
97
94
hashCode = ( hashCode * 397 ) ^ ( Value != null ? Value . GetHashCode ( ) : 0 ) ;
98
- hashCode = ( hashCode * 397 ) ^ ( int ) Type ;
99
- hashCode = ( hashCode * 397 ) ^ ( int ) DataFormat ;
95
+ hashCode = ( hashCode * 397 ) ^ ( int ) Type ;
96
+ hashCode = ( hashCode * 397 ) ^ ( int ) DataFormat ;
100
97
hashCode = ( hashCode * 397 ) ^ ( ContentType != null ? ContentType . GetHashCode ( ) : 0 ) ;
101
98
return hashCode ;
102
99
}
103
100
}
104
101
// ReSharper enable NonReadonlyMemberInGetHashCode
105
102
}
106
103
107
- public class XmlParameter : Parameter
108
- {
109
- public XmlParameter ( string name , object value , string ? xmlNamespace = null ) : base ( name , value , ParameterType . RequestBody )
110
- {
104
+ public class XmlParameter : Parameter {
105
+ public XmlParameter ( string name , object value , string ? xmlNamespace = null ) : base ( name , value , ParameterType . RequestBody ) {
111
106
XmlNamespace = xmlNamespace ;
112
107
DataFormat = DataFormat . Xml ;
113
108
ContentType = Serialization . ContentType . Xml ;
@@ -116,16 +111,13 @@ public XmlParameter(string name, object value, string? xmlNamespace = null) : ba
116
111
public string ? XmlNamespace { get ; }
117
112
}
118
113
119
- public class JsonParameter : Parameter
120
- {
121
- public JsonParameter ( string name , object value ) : base ( name , value , ParameterType . RequestBody )
122
- {
114
+ public class JsonParameter : Parameter {
115
+ public JsonParameter ( string name , object value ) : base ( name , value , ParameterType . RequestBody ) {
123
116
DataFormat = DataFormat . Json ;
124
117
ContentType = Serialization . ContentType . Json ;
125
118
}
126
119
127
- public JsonParameter ( string name , object value , string contentType ) : base ( name , value , ParameterType . RequestBody )
128
- {
120
+ public JsonParameter ( string name , object value , string contentType ) : base ( name , value , ParameterType . RequestBody ) {
129
121
DataFormat = DataFormat . Json ;
130
122
ContentType = contentType ?? Serialization . ContentType . Json ;
131
123
}
0 commit comments