OSDN Git Service

C#7.0で追加されたthrow式の構文を使用する
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 18 Nov 2016 12:51:24 +0000 (21:51 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 11 Mar 2017 18:31:22 +0000 (03:31 +0900)
OpenTween/Connection/Mobypicture.cs
OpenTween/Connection/TwipplePhoto.cs
OpenTween/MediaItem.cs
OpenTween/Models/PostFilterRule.cs
OpenTween/ReaderWriterLockTransaction.cs

index 60a2fd3..be68f2d 100644 (file)
@@ -80,13 +80,8 @@ namespace OpenTween.Connection
 
         public Mobypicture(Twitter twitter, TwitterConfiguration twitterConfig)
         {
-            if (twitter == null)
-                throw new ArgumentNullException(nameof(twitter));
-            if (twitterConfig == null)
-                throw new ArgumentNullException(nameof(twitterConfig));
-
-            this.twitter = twitter;
-            this.twitterConfig = twitterConfig;
+            this.twitter = twitter ?? throw new ArgumentNullException(nameof(twitter));
+            this.twitterConfig = twitterConfig ?? throw new ArgumentNullException(nameof(twitterConfig));
 
             this.mobypictureApi = new MobypictureApi(twitter.Api);
         }
index e36be2a..334f600 100644 (file)
@@ -55,13 +55,8 @@ namespace OpenTween.Connection
 
         public TwipplePhoto(Twitter twitter, TwitterConfiguration twitterConfig)
         {
-            if (twitter == null)
-                throw new ArgumentNullException(nameof(twitter));
-            if (twitterConfig == null)
-                throw new ArgumentNullException(nameof(twitterConfig));
-
-            this.twitter = twitter;
-            this.twitterConfig = twitterConfig;
+            this.twitter = twitter ?? throw new ArgumentNullException(nameof(twitter));
+            this.twitterConfig = twitterConfig ?? throw new ArgumentNullException(nameof(twitterConfig));
 
             this.twippleApi = new TwippleApi(twitter.Api);
         }
index aeb98ad..3273bc1 100644 (file)
@@ -194,10 +194,7 @@ namespace OpenTween
 
         public MemoryImageMediaItem(MemoryImage image)
         {
-            if (image == null)
-                throw new ArgumentNullException(nameof(image));
-
-            this._image = image;
+            this._image = image ?? throw new ArgumentNullException(nameof(image));
 
             var num = Interlocked.Increment(ref _fileNumber);
             this.Path = PathPrefix + num + this._image.ImageFormatExt;
index f8f19d4..87d3feb 100644 (file)
@@ -93,13 +93,7 @@ namespace OpenTween.Models
         public string[] FilterBody
         {
             get { return this._FilterBody; }
-            set
-            {
-                if (value == null)
-                    throw new ArgumentNullException(nameof(value));
-
-                this.SetProperty(ref this._FilterBody, value);
-            }
+            set { this.SetProperty(ref this._FilterBody, value ?? throw new ArgumentNullException(nameof(value))); }
         }
         private string[] _FilterBody = new string[0];
 
@@ -107,13 +101,7 @@ namespace OpenTween.Models
         public string[] ExFilterBody
         {
             get { return this._ExFilterBody; }
-            set
-            {
-                if (value == null)
-                    throw new ArgumentNullException(nameof(value));
-
-                this.SetProperty(ref this._ExFilterBody, value);
-            }
+            set { this.SetProperty(ref this._ExFilterBody, value ?? throw new ArgumentNullException(nameof(value))); }
         }
         private string[] _ExFilterBody = new string[0];
 
index 37b6869..c932d8f 100644 (file)
@@ -34,10 +34,7 @@ namespace OpenTween
 
         public ReadLockTransaction(ReaderWriterLockSlim lockObj)
         {
-            if (lockObj == null)
-                throw new ArgumentNullException(nameof(lockObj));
-
-            this.lockObj = lockObj;
+            this.lockObj = lockObj ?? throw new ArgumentNullException(nameof(lockObj));
             this.lockObj.EnterReadLock();
         }
 
@@ -51,10 +48,7 @@ namespace OpenTween
 
         public WriteLockTransaction(ReaderWriterLockSlim lockObj)
         {
-            if (lockObj == null)
-                throw new ArgumentNullException(nameof(lockObj));
-
-            this.lockObj = lockObj;
+            this.lockObj = lockObj ?? throw new ArgumentNullException(nameof(lockObj));
             this.lockObj.EnterWriteLock();
         }
 
@@ -68,10 +62,7 @@ namespace OpenTween
 
         public UpgradeableReadLockTransaction(ReaderWriterLockSlim lockObj)
         {
-            if (lockObj == null)
-                throw new ArgumentNullException(nameof(lockObj));
-
-            this.lockObj = lockObj;
+            this.lockObj = lockObj ?? throw new ArgumentNullException(nameof(lockObj));
             this.lockObj.EnterUpgradeableReadLock();
         }