lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [43/50] [abbrv] lucenenet git commit: Lucene.Net.Core.Support: Added ExceptionExtensions to provide extension methods for AddSuppressed and GetSuppressed() with the same signatures as in Java, using the Exception.Data dictionary as a backing store.
Date Wed, 15 Mar 2017 23:50:25 GMT
Lucene.Net.Core.Support: Added ExceptionExtensions to provide extension methods for AddSuppressed
and GetSuppressed() with the same signatures as in Java, using the Exception.Data dictionary
as a backing store.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/bdd11633
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/bdd11633
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/bdd11633

Branch: refs/heads/api-work
Commit: bdd11633314285f6389270680b9468c38c35a98f
Parents: a4ee255
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Mar 16 02:52:48 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Mar 16 02:52:48 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj           |  1 +
 .../Support/ExceptionExtensions.cs              | 41 ++++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bdd11633/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj
index 7b667d3..673a129 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -638,6 +638,7 @@
     <Compile Include="Support\DataInputStream.cs" />
     <Compile Include="Support\DataOutputStream.cs" />
     <Compile Include="Support\Codecs\DefaultCodecFactory.cs" />
+    <Compile Include="Support\ExceptionExtensions.cs" />
     <Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" />
     <Compile Include="Support\ExceptionToNullableEnumConvention.cs" />
     <Compile Include="Support\FileStreamExtensions.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bdd11633/src/Lucene.Net.Core/Support/ExceptionExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/ExceptionExtensions.cs b/src/Lucene.Net.Core/Support/ExceptionExtensions.cs
new file mode 100644
index 0000000..b69c6de
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/ExceptionExtensions.cs
@@ -0,0 +1,41 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    /// Extensions to the <see cref="Exception"/> class to allow for
+    /// adding and retrieving suppressed exceptions, like you can do in Java.
+    /// </summary>
+    public static class ExceptionExtensions
+    {
+        public static readonly string SUPPRESSED_EXCEPTIONS_KEY = "Lucene_SuppressedExceptions";
+
+        public static Exception[] GetSuppressed(this Exception e)
+        {
+            return e.GetSuppressedAsList().ToArray();
+        }
+
+        public static IList<Exception> GetSuppressedAsList(this Exception e)
+        {
+            IList<Exception> suppressed;
+            if (!e.Data.Contains(SUPPRESSED_EXCEPTIONS_KEY))
+            {
+                suppressed = new List<Exception>();
+                e.Data.Add(SUPPRESSED_EXCEPTIONS_KEY, suppressed);
+            }
+            else
+            {
+                suppressed = e.Data[SUPPRESSED_EXCEPTIONS_KEY] as IList<Exception>;
+            }
+
+            return suppressed;
+        }
+
+        public static void AddSuppressed(this Exception e, Exception exception)
+        {
+            e.GetSuppressedAsList().Add(exception);
+        }
+    }
+}


Mime
View raw message