Quellcode durchsuchen

[Logs] Implicit bool conversion

feature/authentication-tests
Robin Thoni vor 9 Jahren
Ursprung
Commit
aa0b30f892
2 geänderte Dateien mit 16 neuen und 1 gelöschten Zeilen
  1. 6
    1
      Logs-test/Controllers/ValuesController.cs
  2. 10
    0
      Logs/DBO/OpResult.cs

+ 6
- 1
Logs-test/Controllers/ValuesController.cs Datei anzeigen

@@ -19,7 +19,12 @@ namespace Logs_test.Controllers
19 19
             Logger.Error<int>(ResultStatus.DBError, "my private data", "my public data");
20 20
             Logger.Error<int>(ResultStatus.DBError, "my private/public data", "");
21 21
             Logger.Error<int>(ResultStatus.DBError, "my private data");
22
-            return "value";
22
+            var value = "value";
23
+            if (OpResult<int>.Ok(42))
24
+                value += " ok";
25
+            if (!OpResult<int>.Error(ResultStatus.InputError, "", ""))
26
+                value += " error";
27
+            return value;
23 28
         }
24 29
 
25 30
         // POST api/values

+ 10
- 0
Logs/DBO/OpResult.cs Datei anzeigen

@@ -116,6 +116,16 @@ namespace iiie.Logs.DBO
116 116
             };
117 117
         }
118 118
 
119
+        /// <summary>
120
+        /// Implicit converion to bool
121
+        /// </summary>
122
+        /// <param name="res">The result to be converted</param>
123
+        /// <returns>True if Success, false otherwise</returns>
124
+        public static implicit operator bool(OpResult<T> res)
125
+        {
126
+            return res.Success;
127
+        }
128
+
119 129
         protected OpResult()
120 130
         {
121 131
         }

Laden…
Abbrechen
Speichern