2020using JetBrains . Annotations ;
2121using RestSharp . Validation ;
2222
23- namespace RestSharp
24- {
23+ namespace RestSharp {
2524 /// <summary>
2625 /// Parameter container for REST requests
2726 /// </summary>
2827 [ 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 ) {
3330 if ( type != ParameterType . RequestBody )
3431 Ensure . NotEmpty ( name , nameof ( name ) ) ;
3532
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 ;
3937 }
4038
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 ;
4241
4342 /// <summary>
4443 /// Name of the parameter
@@ -65,49 +64,45 @@ public Parameter(string name, object value, ParameterType type)
6564 /// </summary>
6665 public string ? ContentType { get ; set ; }
6766
67+ internal bool Encode { get ; }
68+
6869 /// <summary>
6970 /// Return a human-readable representation of this parameter
7071 /// </summary>
7172 /// <returns>String</returns>
7273 public override string ToString ( ) => $ "{ Name } ={ Value } ";
7374
74- public bool Equals ( Parameter other )
75- {
75+ public bool Equals ( Parameter ? other ) {
7676 if ( ReferenceEquals ( null , other ) ) return false ;
7777 if ( ReferenceEquals ( this , other ) ) return true ;
7878
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 ;
8484 }
8585
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 ) ) ;
8988
9089 // ReSharper disable NonReadonlyMemberInGetHashCode
91- public override int GetHashCode ( )
92- {
93- unchecked
94- {
90+ public override int GetHashCode ( ) {
91+ unchecked {
9592 var hashCode = Name != null ? Name . GetHashCode ( ) : 0 ;
9693
9794 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 ;
10097 hashCode = ( hashCode * 397 ) ^ ( ContentType != null ? ContentType . GetHashCode ( ) : 0 ) ;
10198 return hashCode ;
10299 }
103100 }
104101 // ReSharper enable NonReadonlyMemberInGetHashCode
105102 }
106103
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 ) {
111106 XmlNamespace = xmlNamespace ;
112107 DataFormat = DataFormat . Xml ;
113108 ContentType = Serialization . ContentType . Xml ;
@@ -116,16 +111,13 @@ public XmlParameter(string name, object value, string? xmlNamespace = null) : ba
116111 public string ? XmlNamespace { get ; }
117112 }
118113
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 ) {
123116 DataFormat = DataFormat . Json ;
124117 ContentType = Serialization . ContentType . Json ;
125118 }
126119
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 ) {
129121 DataFormat = DataFormat . Json ;
130122 ContentType = contentType ?? Serialization . ContentType . Json ;
131123 }
0 commit comments