Skip to content

Commit 35c217c

Browse files
committed
revert to use nameof()
1 parent 86b09bd commit 35c217c

File tree

7 files changed

+204
-224
lines changed

7 files changed

+204
-224
lines changed

src/IBM.WatsonDeveloperCloud.Conversation.v1/ConversationService.cs

Lines changed: 96 additions & 96 deletions
Large diffs are not rendered by default.

src/IBM.WatsonDeveloperCloud.Discovery.v1/DiscoveryService.cs

Lines changed: 87 additions & 87 deletions
Large diffs are not rendered by default.

src/IBM.WatsonDeveloperCloud.LanguageTranslator.v2/LanguageTranslatorService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public LanguageTranslatorService(IClient httpClient) : this()
5858
public TranslationResult Translate(TranslateRequest body)
5959
{
6060
if (body == null)
61-
throw new ArgumentNullException("'body' is required for 'Translate()'");
61+
throw new ArgumentNullException(nameof(body));
6262
TranslationResult result = null;
6363

6464
try
@@ -79,7 +79,7 @@ public TranslationResult Translate(TranslateRequest body)
7979
public IdentifiedLanguages Identify(string text)
8080
{
8181
if (string.IsNullOrEmpty(text))
82-
throw new ArgumentNullException("'text' is required for 'Identify()'");
82+
throw new ArgumentNullException(nameof(text));
8383
IdentifiedLanguages result = null;
8484

8585
try
@@ -119,7 +119,7 @@ public IdentifiableLanguages ListIdentifiableLanguages()
119119
public TranslationModel CreateModel(string baseModelId, string name = null, System.IO.Stream forcedGlossary = null, System.IO.Stream parallelCorpus = null, System.IO.Stream monolingualCorpus = null)
120120
{
121121
if (string.IsNullOrEmpty(baseModelId))
122-
throw new ArgumentNullException("'baseModelId' is required for 'CreateModel()'");
122+
throw new ArgumentNullException(nameof(baseModelId));
123123
TranslationModel result = null;
124124

125125
try
@@ -172,7 +172,7 @@ public TranslationModel CreateModel(string baseModelId, string name = null, Syst
172172
public DeleteModelResult DeleteModel(string modelId)
173173
{
174174
if (string.IsNullOrEmpty(modelId))
175-
throw new ArgumentNullException("'modelId' is required for 'DeleteModel()'");
175+
throw new ArgumentNullException(nameof(modelId));
176176
DeleteModelResult result = null;
177177

178178
try
@@ -193,7 +193,7 @@ public DeleteModelResult DeleteModel(string modelId)
193193
public TranslationModel GetModel(string modelId)
194194
{
195195
if (string.IsNullOrEmpty(modelId))
196-
throw new ArgumentNullException("'modelId' is required for 'GetModel()'");
196+
throw new ArgumentNullException(nameof(modelId));
197197
TranslationModel result = null;
198198

199199
try

src/IBM.WatsonDeveloperCloud.NaturalLanguageUnderstanding.v1/NaturalLanguageUnderstandingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public NaturalLanguageUnderstandingService(IClient httpClient) : this()
6969
public AnalysisResults Analyze(Parameters parameters)
7070
{
7171
if (parameters == null)
72-
throw new ArgumentNullException("'parameters' is required for 'Analyze()'");
72+
throw new ArgumentNullException(nameof(parameters));
7373

7474
if(string.IsNullOrEmpty(VersionDate))
7575
throw new ArgumentNullException("versionDate cannot be null. Use 'NATURAL_LANGUAGE_UNDERSTANDING_VERSION_DATE_2017_02_27'");
@@ -95,7 +95,7 @@ public AnalysisResults Analyze(Parameters parameters)
9595
public InlineResponse200 DeleteModel(string modelId)
9696
{
9797
if (string.IsNullOrEmpty(modelId))
98-
throw new ArgumentNullException("'modelId' is required for 'DeleteModel()'");
98+
throw new ArgumentNullException(nameof(modelId));
9999

100100
if(string.IsNullOrEmpty(VersionDate))
101101
throw new ArgumentNullException("versionDate cannot be null. Use 'NATURAL_LANGUAGE_UNDERSTANDING_VERSION_DATE_2017_02_27'");

src/IBM.WatsonDeveloperCloud.PersonalityInsights.v3/PersonalityInsightsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public PersonalityInsightsService(IClient httpClient) : this()
6666
public Profile Profile(Content content, string contentType, string contentLanguage = null, string acceptLanguage = null, bool? rawScores = null, bool? csvHeaders = null, bool? consumptionPreferences = null)
6767
{
6868
if (content == null)
69-
throw new ArgumentNullException("'content' is required for 'Profile()'");
69+
throw new ArgumentNullException(nameof(content));
7070
if (string.IsNullOrEmpty(contentType))
71-
throw new ArgumentNullException("'contentType' is required for 'Profile()'");
71+
throw new ArgumentNullException(nameof(contentType));
7272

7373
if(string.IsNullOrEmpty(VersionDate))
7474
throw new ArgumentNullException("versionDate cannot be null.");

src/IBM.WatsonDeveloperCloud.ToneAnalyzer.v3/ToneAnalyzerService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public ToneAnalyzerService(IClient httpClient) : this()
6868
public ToneAnalysis Tone(ToneInput toneInput, string contentType, bool? sentences = null, List<string> tones = null, string contentLanguage = null, string acceptLanguage = null)
6969
{
7070
if (toneInput == null)
71-
throw new ArgumentNullException("'toneInput' is required for 'Tone()'");
71+
throw new ArgumentNullException(nameof(toneInput));
7272
if (string.IsNullOrEmpty(contentType))
73-
throw new ArgumentNullException("'contentType' is required for 'Tone()'");
73+
throw new ArgumentNullException(nameof(contentType));
7474

7575
if(string.IsNullOrEmpty(VersionDate))
7676
throw new ArgumentNullException("versionDate cannot be null.");
@@ -102,7 +102,7 @@ public ToneAnalysis Tone(ToneInput toneInput, string contentType, bool? sentence
102102
public UtteranceAnalyses ToneChat(ToneChatInput utterances, string acceptLanguage = null)
103103
{
104104
if (utterances == null)
105-
throw new ArgumentNullException("'utterances' is required for 'ToneChat()'");
105+
throw new ArgumentNullException(nameof(utterances));
106106

107107
if(string.IsNullOrEmpty(VersionDate))
108108
throw new ArgumentNullException("versionDate cannot be null.");

src/IBM.WatsonDeveloperCloud.VisualRecognition.v3/VisualRecognitionService.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ public ClassifyPost Classify(byte[] imageData = null, string imageDataName = nul
122122
ClassifyPost result = null;
123123

124124
if (imageData == null && (urls == null || urls.Length < 1))
125-
throw new ArgumentNullException(string.Format("{0} and {1} are required for 'Classify()'", "'imageData'", "'urls'"));
125+
throw new ArgumentNullException(string.Format("{0} or {1} are required for 'Classify()'", nameof(imageData), "'urls'"));
126126

127127
if (imageData != null)
128128
{
129129
if (string.IsNullOrEmpty(imageDataName) || string.IsNullOrEmpty(imageDataMimeType))
130-
throw new ArgumentException(string.Format("{0} or {1} are required for 'Classify()'", "'imageDataName'", "'imageDataMimeType'"));
130+
throw new ArgumentException(string.Format("{0} and {1} are required for 'Classify()'", nameof(imageDataName),nameof(imageDataMimeType)));
131131
}
132132

133133
if (owners != null)
@@ -208,12 +208,12 @@ public Faces DetectFaces(byte[] imageData = null, string imageDataName = null, s
208208
Faces result = null;
209209

210210
if (imageData == null && (urls == null || urls.Length < 1))
211-
throw new ArgumentNullException(string.Format("{0} and {1} are required for 'DetectFaces()'", "'imageData'", "'urls'"));
211+
throw new ArgumentNullException(string.Format("{0} or {1} are required for 'DetectFaces()'", nameof(imageData), "'urls'"));
212212

213213
if (imageData != null)
214214
{
215215
if (string.IsNullOrEmpty(imageDataName) || string.IsNullOrEmpty(imageDataMimeType))
216-
throw new ArgumentNullException(string.Format("{0} or {1} are required for 'DetectFaces()'", "'imageDataName'", "'imageDataMimeType'"));
216+
throw new ArgumentNullException(string.Format("{0} and {1} are required for 'DetectFaces()'", nameof(imageDataName), nameof(imageDataMimeType)));
217217
}
218218

219219
try
@@ -310,10 +310,10 @@ public GetClassifiersPerClassifierVerbose CreateClassifier(string classifierName
310310
GetClassifiersPerClassifierVerbose result = null;
311311

312312
if (string.IsNullOrEmpty(classifierName))
313-
throw new ArgumentNullException("'classifierName' is required for 'CreateClassifier()'");
313+
throw new ArgumentNullException(nameof(classifierName));
314314

315315
if (positiveExamplesData == null)
316-
throw new ArgumentNullException("'positiveExamplesData' is required for 'GetClassifier()'");
316+
throw new ArgumentNullException(nameof(positiveExamplesData));
317317

318318
if (positiveExamplesData.Count < 2 && negativeExamplesData == null)
319319
throw new ArgumentNullException("Training a Visual Recognition classifier requires at least two positive example files or one positive example and negative example file.");
@@ -361,7 +361,7 @@ public object DeleteClassifier(string classifierId)
361361
object result = null;
362362

363363
if (string.IsNullOrEmpty(classifierId))
364-
throw new ArgumentNullException("'classifierId' is required for DeleteClassifier()");
364+
throw new ArgumentNullException(nameof(classifierId));
365365

366366
try
367367
{
@@ -384,7 +384,7 @@ public object DeleteClassifier(string classifierId)
384384
public GetClassifiersPerClassifierVerbose GetClassifier(string classifierId)
385385
{
386386
if (string.IsNullOrEmpty(classifierId))
387-
throw new ArgumentNullException("'classifierId' is required for 'GetClassifier()'");
387+
throw new ArgumentNullException(nameof(classifierId));
388388

389389
GetClassifiersPerClassifierVerbose result = null;
390390

@@ -409,7 +409,7 @@ public GetClassifiersPerClassifierVerbose UpdateClassifier(string classifierId,
409409
GetClassifiersPerClassifierVerbose result = null;
410410

411411
if (string.IsNullOrEmpty(classifierId))
412-
throw new ArgumentNullException("'classifierId' is required for 'UpdateClassifier()'");
412+
throw new ArgumentNullException(nameof(classifierId));
413413

414414
if (positiveExamplesData == null && negativeExamplesData == null)
415415
throw new ArgumentNullException("Positive example data and/or negative example data are required to update a classifier.");
@@ -451,25 +451,5 @@ public GetClassifiersPerClassifierVerbose UpdateClassifier(string classifierId,
451451
return result;
452452
}
453453
#endregion
454-
455-
#region Utils
456-
private string GetImageMimeTypeFromFilename(string filename)
457-
{
458-
string imageMimeType = "";
459-
if (!string.IsNullOrEmpty(filename))
460-
{
461-
string ext = Path.GetExtension(filename).ToLower();
462-
463-
if (ext == ".jpg" || ext == ".jpeg")
464-
imageMimeType = "image/jpeg";
465-
else if (ext == ".png")
466-
imageMimeType = "image/png";
467-
else
468-
throw new ArgumentOutOfRangeException(nameof(imageMimeType), "Only jpg and png images are accepted.");
469-
}
470-
471-
return imageMimeType;
472-
}
473-
#endregion
474454
}
475455
}

0 commit comments

Comments
 (0)