Parcourir la source

[Logs] Shorter OpResult conversion method

feature/authentication-tests
Robin Thoni il y a 9 ans
Parent
révision
11db02a352
2 fichiers modifiés avec 16 ajouts et 0 suppressions
  1. 6
    0
      Logs-test/Controllers/ValuesController.cs
  2. 10
    0
      Logs/DBO/OpResult.cs

+ 6
- 0
Logs-test/Controllers/ValuesController.cs Voir le fichier

@@ -27,6 +27,12 @@ namespace Logs_test.Controllers
27 27
             return value;
28 28
         }
29 29
 
30
+        public OpResult<int> Test()
31
+        {
32
+            var res = OpResult<bool>.Error(ResultStatus.DBError, "Test");
33
+            return res.To<int>();
34
+        }
35
+
30 36
         // POST api/values
31 37
         public void Post([FromBody]string value)
32 38
         {

+ 10
- 0
Logs/DBO/OpResult.cs Voir le fichier

@@ -116,6 +116,16 @@ namespace iiie.Logs.DBO
116 116
             };
117 117
         }
118 118
 
119
+        /// <summary>
120
+        /// Translate an error to another type
121
+        /// </summary>
122
+        /// <typeparam name="T2">The original type</typeparam>
123
+        /// <returns>The original error with the type T</returns>
124
+        public OpResult<T2> To<T2>()
125
+        {
126
+            return OpResult<T2>.Error(this);
127
+        }
128
+
119 129
         /// <summary>
120 130
         /// Implicit converion to bool
121 131
         /// </summary>

Chargement…
Annuler
Enregistrer