@@ -649,67 +649,12 @@ bool paramsContainsCancellationToken
649
649
parameterInfo = parameterMapValue ;
650
650
if ( parameterInfo . IsObjectPropertyParameter )
651
651
{
652
- foreach ( var propertyInfo in parameterInfo . ParameterProperties )
653
- {
654
- var propertyObject = propertyInfo . PropertyInfo . GetValue ( param ) ;
655
- urlTarget = Regex . Replace (
656
- urlTarget ,
657
- "{" + propertyInfo . Name + "}" ,
658
- Uri . EscapeDataString (
659
- settings . UrlParameterFormatter . Format (
660
- propertyObject ,
661
- propertyInfo . PropertyInfo ,
662
- propertyInfo . PropertyInfo . PropertyType
663
- ) ?? string . Empty
664
- ) ,
665
- RegexOptions . IgnoreCase | RegexOptions . CultureInvariant
666
- ) ;
667
- }
652
+ urlTarget = AddObjectParametersToUrl ( parameterInfo , param , urlTarget ) ;
668
653
//don't continue here as we want it to fall through so any parameters on this object not bound here get passed as query parameters
669
654
}
670
655
else
671
656
{
672
- string pattern ;
673
- string replacement ;
674
- if ( parameterMapValue . Type == ParameterType . RoundTripping )
675
- {
676
- pattern = $@ "{{\*\*{ parameterMapValue . Name } }}";
677
- var paramValue = ( string ) param ;
678
- replacement = string . Join (
679
- "/" ,
680
- paramValue
681
- . Split ( '/' )
682
- . Select (
683
- s =>
684
- Uri . EscapeDataString (
685
- settings . UrlParameterFormatter . Format (
686
- s ,
687
- restMethod . ParameterInfoArray [ i ] ,
688
- restMethod . ParameterInfoArray [ i ] . ParameterType
689
- ) ?? string . Empty
690
- )
691
- )
692
- ) ;
693
- }
694
- else
695
- {
696
- pattern = "{" + parameterMapValue . Name + "}" ;
697
- replacement = Uri . EscapeDataString (
698
- settings . UrlParameterFormatter . Format (
699
- param ,
700
- restMethod . ParameterInfoArray [ i ] ,
701
- restMethod . ParameterInfoArray [ i ] . ParameterType
702
- ) ?? string . Empty
703
- ) ;
704
- }
705
-
706
- urlTarget = Regex . Replace (
707
- urlTarget ,
708
- pattern ,
709
- replacement ,
710
- RegexOptions . IgnoreCase | RegexOptions . CultureInvariant
711
- ) ;
712
-
657
+ urlTarget = AddValueParameterToUrl ( restMethod , parameterMapValue , param , i , urlTarget ) ;
713
658
isParameterMappedToRequest = true ;
714
659
}
715
660
}
@@ -721,7 +666,6 @@ bool paramsContainsCancellationToken
721
666
)
722
667
{
723
668
AddBodyToRequest ( restMethod , param , ret ) ;
724
-
725
669
isParameterMappedToRequest = true ;
726
670
}
727
671
@@ -784,7 +728,6 @@ bool paramsContainsCancellationToken
784
728
)
785
729
{
786
730
AddQueryParameters ( restMethod , queryAttribute , param , queryParamsToAdd , i , parameterInfo ) ;
787
-
788
731
continue ;
789
732
}
790
733
@@ -818,6 +761,74 @@ bool paramsContainsCancellationToken
818
761
} ;
819
762
}
820
763
764
+ string AddObjectParametersToUrl ( RestMethodParameterInfo parameterInfo , object param , string urlTarget )
765
+ {
766
+ foreach ( var propertyInfo in parameterInfo . ParameterProperties )
767
+ {
768
+ var propertyObject = propertyInfo . PropertyInfo . GetValue ( param ) ;
769
+ urlTarget = Regex . Replace (
770
+ urlTarget ,
771
+ "{" + propertyInfo . Name + "}" ,
772
+ Uri . EscapeDataString (
773
+ settings . UrlParameterFormatter . Format (
774
+ propertyObject ,
775
+ propertyInfo . PropertyInfo ,
776
+ propertyInfo . PropertyInfo . PropertyType
777
+ ) ?? string . Empty
778
+ ) ,
779
+ RegexOptions . IgnoreCase | RegexOptions . CultureInvariant
780
+ ) ;
781
+ }
782
+
783
+ return urlTarget ;
784
+ }
785
+
786
+ string AddValueParameterToUrl ( RestMethodInfoInternal restMethod , RestMethodParameterInfo parameterMapValue ,
787
+ object param , int i , string urlTarget )
788
+ {
789
+ string pattern ;
790
+ string replacement ;
791
+ if ( parameterMapValue . Type == ParameterType . RoundTripping )
792
+ {
793
+ pattern = $@ "{{\*\*{ parameterMapValue . Name } }}";
794
+ var paramValue = ( string ) param ;
795
+ replacement = string . Join (
796
+ "/" ,
797
+ paramValue
798
+ . Split ( '/' )
799
+ . Select (
800
+ s =>
801
+ Uri . EscapeDataString (
802
+ settings . UrlParameterFormatter . Format (
803
+ s ,
804
+ restMethod . ParameterInfoArray [ i ] ,
805
+ restMethod . ParameterInfoArray [ i ] . ParameterType
806
+ ) ?? string . Empty
807
+ )
808
+ )
809
+ ) ;
810
+ }
811
+ else
812
+ {
813
+ pattern = "{" + parameterMapValue . Name + "}" ;
814
+ replacement = Uri . EscapeDataString (
815
+ settings . UrlParameterFormatter . Format (
816
+ param ,
817
+ restMethod . ParameterInfoArray [ i ] ,
818
+ restMethod . ParameterInfoArray [ i ] . ParameterType
819
+ ) ?? string . Empty
820
+ ) ;
821
+ }
822
+
823
+ urlTarget = Regex . Replace (
824
+ urlTarget ,
825
+ pattern ,
826
+ replacement ,
827
+ RegexOptions . IgnoreCase | RegexOptions . CultureInvariant
828
+ ) ;
829
+ return urlTarget ;
830
+ }
831
+
821
832
void AddBodyToRequest ( RestMethodInfoInternal restMethod , object param , HttpRequestMessage ret )
822
833
{
823
834
if ( param is HttpContent httpContentParam )
@@ -940,11 +951,7 @@ void AddMultiPart(RestMethodInfoInternal restMethod, int i, object param,
940
951
}
941
952
942
953
// Check to see if it's an IEnumerable
943
- var itemValue = param ;
944
- var enumerable = itemValue as IEnumerable < object > ;
945
- var typeIsCollection = enumerable != null ;
946
-
947
- if ( typeIsCollection )
954
+ if ( param is IEnumerable < object > enumerable )
948
955
{
949
956
foreach ( var item in enumerable ! )
950
957
{
@@ -953,7 +960,7 @@ void AddMultiPart(RestMethodInfoInternal restMethod, int i, object param,
953
960
}
954
961
else
955
962
{
956
- AddMultipartItem ( multiPartContent ! , itemName , parameterName , itemValue ) ;
963
+ AddMultipartItem ( multiPartContent ! , itemName , parameterName , param ) ;
957
964
}
958
965
}
959
966
0 commit comments