File tree Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -116,19 +116,23 @@ public static PublicationAddress Parse(string uriLikeString)
116
116
return null ;
117
117
}
118
118
119
- public static PublicationAddress TryParse ( string uriLikeString )
119
+ public static bool TryParse ( string uriLikeString , out PublicationAddress result )
120
120
{
121
121
// Callers such as IBasicProperties.ReplyToAddress
122
122
// expect null result for invalid input.
123
123
// The regex.Match() throws on null arguments so we perform explicit check here
124
124
if ( uriLikeString == null )
125
125
{
126
- return null ;
126
+ result = null ;
127
+ return false ;
127
128
} else {
128
129
try {
129
- return Parse ( uriLikeString ) ;
130
+ var res = Parse ( uriLikeString ) ;
131
+ result = res ;
132
+ return true ;
130
133
} catch {
131
- return null ;
134
+ result = null ;
135
+ return false ;
132
136
}
133
137
}
134
138
}
Original file line number Diff line number Diff line change @@ -115,7 +115,11 @@ public bool Persistent
115
115
/// </summary>
116
116
public PublicationAddress ReplyToAddress
117
117
{
118
- get { return PublicationAddress . TryParse ( ReplyTo ) ; }
118
+ get {
119
+ PublicationAddress result ;
120
+ PublicationAddress . TryParse ( ReplyTo , out result ) ;
121
+ return result ;
122
+ }
119
123
set { ReplyTo = value . ToString ( ) ; }
120
124
}
121
125
Original file line number Diff line number Diff line change @@ -135,7 +135,9 @@ public void TestProperties_ReplyTo(
135
135
136
136
// Assert
137
137
bool isReplyToPresent = replyTo != null ;
138
- string replyToAddress = PublicationAddress . TryParse ( replyTo ) ? . ToString ( ) ;
138
+ PublicationAddress result ;
139
+ PublicationAddress . TryParse ( replyTo , out result ) ;
140
+ string replyToAddress = result ? . ToString ( ) ;
139
141
Assert . AreEqual ( isReplyToPresent , subject . IsReplyToPresent ( ) ) ;
140
142
141
143
var writer = new Impl . ContentHeaderPropertyWriter ( new byte [ 1024 ] ) ;
Original file line number Diff line number Diff line change @@ -71,9 +71,15 @@ public void TestParseFailWithUnparseableInput()
71
71
[ Test ]
72
72
public void TestTryParseFail ( )
73
73
{
74
- Assert . IsNull ( PublicationAddress . TryParse ( null ) ) ;
75
- Assert . IsNull ( PublicationAddress . TryParse ( "not a valid URI" ) ) ;
76
- Assert . IsNull ( PublicationAddress . TryParse ( "}}}}}}}}" ) ) ;
74
+ PublicationAddress result ;
75
+ PublicationAddress . TryParse ( null , out result ) ;
76
+ Assert . IsNull ( result ) ;
77
+
78
+ PublicationAddress . TryParse ( "not a valid URI" , out result ) ;
79
+ Assert . IsNull ( result ) ;
80
+
81
+ PublicationAddress . TryParse ( "}}}}}}}}" , out result ) ;
82
+ Assert . IsNull ( result ) ;
77
83
}
78
84
79
85
[ Test ]
You can’t perform that action at this time.
0 commit comments