@@ -1375,7 +1375,11 @@ internal static BlobLegalHoldResult ToBlobLegalHoldInfo(this ResponseWithHeaders
13751375 #endregion
13761376
13771377 #region ValidateConditionsNotPresent
1378- internal static void ValidateConditionsNotPresent ( this BlobLeaseRequestConditions requestConditions , BlobRequestConditionProperty invalidConditions )
1378+ internal static void ValidateRequestConditionsNotPresent (
1379+ this BlobRequestConditions requestConditions ,
1380+ BlobRequestConditionProperty invalidConditions ,
1381+ string operationName ,
1382+ string parameterName )
13791383 {
13801384 if ( AppContextSwitchHelper . GetConfigValue (
13811385 Constants . DisableRequestConditionsValidationSwitchName ,
@@ -1389,63 +1393,125 @@ internal static void ValidateConditionsNotPresent(this BlobLeaseRequestCondition
13891393 return ;
13901394 }
13911395
1396+ List < string > invalidList = null ;
1397+ requestConditions . ValidateConditionsNotPresent (
1398+ invalidConditions ,
1399+ ref invalidList ) ;
1400+
1401+ if ( invalidList ? . Count > 0 )
1402+ {
1403+ string unsupportedString = string . Join ( ", " , invalidList ) ;
1404+ throw new ArgumentException (
1405+ $ "{ operationName } does not support the { unsupportedString } condition(s).",
1406+ parameterName ) ;
1407+ }
1408+ }
1409+
1410+ internal static void ValidateConditionsNotPresent (
1411+ this BlobLeaseRequestConditions requestConditions ,
1412+ BlobRequestConditionProperty invalidConditions ,
1413+ string operationName ,
1414+ string parameterName )
1415+ {
1416+ if ( AppContextSwitchHelper . GetConfigValue (
1417+ Constants . DisableRequestConditionsValidationSwitchName ,
1418+ Constants . DisableRequestConditionsValidationEnvVar ) )
1419+ {
1420+ return ;
1421+ }
1422+
1423+ if ( requestConditions == null )
1424+ {
1425+ return ;
1426+ }
1427+
1428+ List < string > invalidList = null ;
1429+ requestConditions . ValidateConditionsNotPresent (
1430+ invalidConditions , ref invalidList ) ;
1431+
1432+ if ( invalidList ? . Count > 0 )
1433+ {
1434+ string unsupportedString = string . Join ( ", " , invalidList ) ;
1435+ throw new ArgumentException (
1436+ $ "{ operationName } does not support the { unsupportedString } condition(s).",
1437+ parameterName ) ;
1438+ }
1439+ }
1440+
1441+ internal static void ValidateConditionsNotPresent (
1442+ this BlobLeaseRequestConditions requestConditions ,
1443+ BlobRequestConditionProperty invalidConditions ,
1444+ ref List < string > invalidList )
1445+ {
1446+ if ( requestConditions == null )
1447+ {
1448+ return ;
1449+ }
1450+
13921451 if ( ( invalidConditions & BlobRequestConditionProperty . TagConditions ) == BlobRequestConditionProperty . TagConditions
13931452 && requestConditions . TagConditions != null )
13941453 {
1395- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . TagConditions ) } is not applicable to this API.") ;
1454+ invalidList ??= new List < string > ( ) ;
1455+ invalidList . Add ( nameof ( requestConditions . TagConditions ) ) ;
13961456 }
13971457
13981458 if ( ( invalidConditions & BlobRequestConditionProperty . IfModifiedSince ) == BlobRequestConditionProperty . IfModifiedSince
13991459 && requestConditions . IfModifiedSince != null )
14001460 {
1401- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . IfModifiedSince ) } is not applicable to this API.") ;
1461+ invalidList ??= new List < string > ( ) ;
1462+ invalidList . Add ( nameof ( BlobRequestConditions . IfModifiedSince ) ) ;
14021463 }
14031464
14041465 if ( ( invalidConditions & BlobRequestConditionProperty . IfUnmodifiedSince ) == BlobRequestConditionProperty . IfUnmodifiedSince
14051466 && requestConditions . IfUnmodifiedSince != null )
14061467 {
1407- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . IfUnmodifiedSince ) } is not applicable to this API.") ;
1468+ invalidList ??= new List < string > ( ) ;
1469+ invalidList . Add ( nameof ( BlobRequestConditions . IfUnmodifiedSince ) ) ;
14081470 }
14091471
14101472 if ( ( invalidConditions & BlobRequestConditionProperty . IfMatch ) == BlobRequestConditionProperty . IfMatch
14111473 && requestConditions . IfMatch != null )
14121474 {
1413- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . IfMatch ) } is not applicable to this API.") ;
1475+ invalidList ??= new List < string > ( ) ;
1476+ invalidList . Add ( nameof ( BlobRequestConditions . IfMatch ) ) ;
14141477 }
14151478
14161479 if ( ( invalidConditions & BlobRequestConditionProperty . IfNoneMatch ) == BlobRequestConditionProperty . IfNoneMatch
14171480 && requestConditions . IfNoneMatch != null )
14181481 {
1419- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . IfNoneMatch ) } is not applicable to this API.") ;
1482+ invalidList ??= new List < string > ( ) ;
1483+ invalidList . Add ( nameof ( BlobRequestConditions . IfNoneMatch ) ) ;
14201484 }
14211485 }
14221486
1423- internal static void ValidateConditionsNotPresent ( this BlobRequestConditions requestConditions , BlobRequestConditionProperty invalidConditions )
1487+ internal static void ValidateConditionsNotPresent (
1488+ this BlobRequestConditions requestConditions ,
1489+ BlobRequestConditionProperty invalidConditions ,
1490+ ref List < string > invalidList )
14241491 {
1425- if ( AppContextSwitchHelper . GetConfigValue (
1426- Constants . DisableRequestConditionsValidationSwitchName ,
1427- Constants . DisableRequestConditionsValidationEnvVar ) )
1428- {
1429- return ;
1430- }
1431-
14321492 if ( requestConditions == null )
14331493 {
14341494 return ;
14351495 }
14361496
14371497 // Validate BlobLeaseRequestConditions conditions.
1438- ( ( BlobLeaseRequestConditions ) requestConditions ) . ValidateConditionsNotPresent ( invalidConditions ) ;
1498+ ( ( BlobLeaseRequestConditions ) requestConditions ) . ValidateConditionsNotPresent (
1499+ invalidConditions , ref invalidList ) ;
14391500
14401501 // Validate BlobRequestConditions specific conditions.
14411502 if ( ( invalidConditions & BlobRequestConditionProperty . LeaseId ) == BlobRequestConditionProperty . LeaseId
14421503 && requestConditions . LeaseId != null )
14431504 {
1444- throw new ArgumentException ( $ "{ nameof ( BlobRequestConditions . LeaseId ) } is not applicable to this API.") ;
1505+ invalidList ??= new List < string > ( ) ;
1506+ invalidList . Add ( nameof ( BlobRequestConditions . LeaseId ) ) ;
14451507 }
14461508 }
14471509
1448- internal static void ValidateConditionsNotPresent ( this AppendBlobRequestConditions requestConditions , BlobRequestConditionProperty invalidConditions )
1510+ internal static void ValidateConditionsNotPresent (
1511+ this AppendBlobRequestConditions requestConditions ,
1512+ BlobRequestConditionProperty invalidConditions ,
1513+ string operationName ,
1514+ string parameterName )
14491515 {
14501516 if ( AppContextSwitchHelper . GetConfigValue (
14511517 Constants . DisableRequestConditionsValidationSwitchName ,
@@ -1459,24 +1525,41 @@ internal static void ValidateConditionsNotPresent(this AppendBlobRequestConditio
14591525 return ;
14601526 }
14611527
1528+ List < string > invalidList = null ;
1529+
14621530 // Validate BlobRequestConditions
1463- ( ( BlobRequestConditions ) requestConditions ) . ValidateConditionsNotPresent ( invalidConditions ) ;
1531+ ( ( BlobRequestConditions ) requestConditions ) . ValidateConditionsNotPresent (
1532+ invalidConditions , ref invalidList ) ;
14641533
14651534 // Validate AppendBlobRequestConditions specific conditions.
14661535 if ( ( invalidConditions & BlobRequestConditionProperty . IfAppendPositionEqual ) == BlobRequestConditionProperty . IfAppendPositionEqual
14671536 && requestConditions . IfAppendPositionEqual != null )
14681537 {
1469- throw new ArgumentException ( $ "{ nameof ( AppendBlobRequestConditions . IfAppendPositionEqual ) } is not applicable to this API.") ;
1538+ invalidList ??= new List < string > ( ) ;
1539+ invalidList . Add ( nameof ( AppendBlobRequestConditions . IfAppendPositionEqual ) ) ;
14701540 }
14711541
14721542 if ( ( invalidConditions & BlobRequestConditionProperty . IfMaxSizeLessThanOrEqual ) == BlobRequestConditionProperty . IfMaxSizeLessThanOrEqual
14731543 && requestConditions . IfMaxSizeLessThanOrEqual != null )
14741544 {
1475- throw new ArgumentException ( $ "{ nameof ( AppendBlobRequestConditions . IfMaxSizeLessThanOrEqual ) } is not applicable to this API.") ;
1545+ invalidList ??= new List < string > ( ) ;
1546+ invalidList . Add ( nameof ( AppendBlobRequestConditions . IfMaxSizeLessThanOrEqual ) ) ;
1547+ }
1548+
1549+ if ( invalidList ? . Count > 0 )
1550+ {
1551+ string unsupportedString = string . Join ( ", " , invalidList ) ;
1552+ throw new ArgumentException (
1553+ $ "{ operationName } does not support the { unsupportedString } condition(s).",
1554+ parameterName ) ;
14761555 }
14771556 }
14781557
1479- internal static void ValidateConditionsNotPresent ( this PageBlobRequestConditions requestConditions , BlobRequestConditionProperty invalidConditions )
1558+ internal static void ValidateConditionsNotPresent (
1559+ this PageBlobRequestConditions requestConditions ,
1560+ BlobRequestConditionProperty invalidConditions ,
1561+ string operationName ,
1562+ string parameterName )
14801563 {
14811564 if ( AppContextSwitchHelper . GetConfigValue (
14821565 Constants . DisableRequestConditionsValidationSwitchName ,
@@ -1490,26 +1573,40 @@ internal static void ValidateConditionsNotPresent(this PageBlobRequestConditions
14901573 return ;
14911574 }
14921575
1576+ List < string > invalidList = null ;
1577+
14931578 // Validate BlobRequestConditions
1494- ( ( BlobRequestConditions ) requestConditions ) . ValidateConditionsNotPresent ( invalidConditions ) ;
1579+ ( ( BlobRequestConditions ) requestConditions ) . ValidateConditionsNotPresent (
1580+ invalidConditions , ref invalidList ) ;
14951581
14961582 // Validate PageBlobRequestConditions specific conditions.
14971583 if ( ( invalidConditions & BlobRequestConditionProperty . IfSequenceNumberLessThan ) == BlobRequestConditionProperty . IfSequenceNumberLessThan
14981584 && requestConditions . IfSequenceNumberLessThan != null )
14991585 {
1500- throw new ArgumentException ( $ "{ nameof ( PageBlobRequestConditions . IfSequenceNumberLessThan ) } is not applicable to this API.") ;
1586+ invalidList ??= new List < string > ( ) ;
1587+ invalidList . Add ( nameof ( PageBlobRequestConditions . IfSequenceNumberLessThan ) ) ;
15011588 }
15021589
15031590 if ( ( invalidConditions & BlobRequestConditionProperty . IfSequenceNumberLessThanOrEqual ) == BlobRequestConditionProperty . IfSequenceNumberLessThanOrEqual
15041591 && requestConditions . IfSequenceNumberLessThanOrEqual != null )
15051592 {
1506- throw new ArgumentException ( $ "{ nameof ( PageBlobRequestConditions . IfSequenceNumberLessThanOrEqual ) } is not applicable to this API.") ;
1593+ invalidList ??= new List < string > ( ) ;
1594+ invalidList . Add ( nameof ( PageBlobRequestConditions . IfSequenceNumberLessThanOrEqual ) ) ;
15071595 }
15081596
15091597 if ( ( invalidConditions & BlobRequestConditionProperty . IfSequenceNumberEqual ) == BlobRequestConditionProperty . IfSequenceNumberEqual
15101598 && requestConditions . IfSequenceNumberEqual != null )
15111599 {
1512- throw new ArgumentException ( $ "{ nameof ( PageBlobRequestConditions . IfSequenceNumberEqual ) } is not applicable to this API.") ;
1600+ invalidList ??= new List < string > ( ) ;
1601+ invalidList . Add ( nameof ( PageBlobRequestConditions . IfSequenceNumberEqual ) ) ;
1602+ }
1603+
1604+ if ( invalidList ? . Count > 0 )
1605+ {
1606+ string unsupportedString = string . Join ( ", " , invalidList ) ;
1607+ throw new ArgumentException (
1608+ $ "{ operationName } does not support the { unsupportedString } condition(s).",
1609+ parameterName ) ;
15131610 }
15141611 }
15151612 #endregion
0 commit comments