From fee90819b80ee1b73f8287b528f6c9c696856ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E5=96=B5=E5=A4=A7=E4=BA=BA?= Date: Sat, 20 Jul 2019 14:06:50 +0800 Subject: [PATCH] removed CodeStandardException. --- .../CatLib/TestsApplication.cs | 12 ++-- .../Container/TestsContainer.cs | 12 ++-- src/CatLib.Core/CatLib/Application.cs | 12 ++-- src/CatLib.Core/Container/Container.cs | 10 ++-- .../Exception/CodeStandardException.cs | 60 ------------------- 5 files changed, 23 insertions(+), 83 deletions(-) delete mode 100644 src/CatLib.Core/Support/Exception/CodeStandardException.cs diff --git a/src/CatLib.Core.Tests/CatLib/TestsApplication.cs b/src/CatLib.Core.Tests/CatLib/TestsApplication.cs index cf27b19..a7175a5 100644 --- a/src/CatLib.Core.Tests/CatLib/TestsApplication.cs +++ b/src/CatLib.Core.Tests/CatLib/TestsApplication.cs @@ -41,7 +41,7 @@ public void TestGetFileVersion() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestBootstrapRepeat() { application.Bootstrap(); @@ -50,7 +50,7 @@ public void TestBootstrapRepeat() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestInitRepeat() { application.Bootstrap(); @@ -59,7 +59,7 @@ public void TestInitRepeat() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestInitNoBootstrap() { application.Init(); @@ -116,7 +116,7 @@ public void TestRegisterRepeat() } [TestMethod] - [ExpectedExceptionAndMessage(typeof(CodeStandardException))] + [ExpectedExceptionAndMessage(typeof(LogicException))] public void TestInitingRegister() { var foo = new Mock(); @@ -133,7 +133,7 @@ public void TestInitingRegister() } [TestMethod] - [ExpectedExceptionAndMessage(typeof(CodeStandardException))] + [ExpectedExceptionAndMessage(typeof(LogicException))] public void TestTerminateRegister() { var foo = new Mock(); @@ -214,7 +214,7 @@ public void TestInitAfterRegister() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestRegistingMake() { var foo = new Mock(); diff --git a/src/CatLib.Core.Tests/Container/TestsContainer.cs b/src/CatLib.Core.Tests/Container/TestsContainer.cs index ceebc8d..8e378b4 100644 --- a/src/CatLib.Core.Tests/Container/TestsContainer.cs +++ b/src/CatLib.Core.Tests/Container/TestsContainer.cs @@ -189,7 +189,7 @@ public void TestBindIllegal() container.Bind(null, (container, args) => "invalid service name", false); }); - Assert.ThrowsException(() => + Assert.ThrowsException(() => { container.Bind("$foo", (container, args) => "Illegal placeholder", false); }); @@ -234,7 +234,7 @@ public void TestAlias() } [TestMethod] - [DataRow("bar-alias", "bar", typeof(CodeStandardException), "Set an alias for a service that does not exist.")] + [DataRow("bar-alias", "bar", typeof(LogicException), "Set an alias for a service that does not exist.")] [DataRow(null, "bar", typeof(ArgumentNullException), "Alias name is null.")] [DataRow("baz", null, typeof(ArgumentNullException), "Service name is null.")] [DataRow("foo", "foo", typeof(LogicException), "Alias is same as service")] @@ -652,7 +652,7 @@ public void TestInstance() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] [DataRow("foo:bar")] [DataRow("$foo")] [DataRow("foo@bar")] @@ -662,7 +662,7 @@ public void TestInstanceIllegalChars(string service) } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestInstanceNotAllowedSameObject() { var foo = new object(); @@ -750,7 +750,7 @@ public void TestFlush() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestFlushInstanceService() { container.Bind("foo", typeof(Foo), true) @@ -822,7 +822,7 @@ public void TestVariantForceGivenNull() } [TestMethod] - [ExpectedException(typeof(CodeStandardException))] + [ExpectedException(typeof(LogicException))] public void TestReboundNotExistsService() { container.OnRebound("foobar", (instance) => diff --git a/src/CatLib.Core/CatLib/Application.cs b/src/CatLib.Core/CatLib/Application.cs index dd9510a..db4d252 100644 --- a/src/CatLib.Core/CatLib/Application.cs +++ b/src/CatLib.Core/CatLib/Application.cs @@ -195,7 +195,7 @@ public virtual void Bootstrap(params IBootstrap[] bootstraps) if (bootstrapped || Process != StartProcess.Construct) { - throw new CodeStandardException($"Cannot repeatedly trigger the {nameof(Bootstrap)}()"); + throw new LogicException($"Cannot repeatedly trigger the {nameof(Bootstrap)}()"); } Process = StartProcess.Bootstrap; @@ -239,12 +239,12 @@ public virtual void Init() { if (!bootstrapped) { - throw new CodeStandardException($"You must call {nameof(Bootstrap)}() first."); + throw new LogicException($"You must call {nameof(Bootstrap)}() first."); } if (inited || Process != StartProcess.Bootstraped) { - throw new CodeStandardException($"Cannot repeatedly trigger the {nameof(Init)}()"); + throw new LogicException($"Cannot repeatedly trigger the {nameof(Init)}()"); } Process = StartProcess.Init; @@ -281,12 +281,12 @@ public virtual void Register(IServiceProvider provider, bool force = false) if (Process == StartProcess.Initing) { - throw new CodeStandardException($"Unable to add service provider during {nameof(StartProcess.Initing)}"); + throw new LogicException($"Unable to add service provider during {nameof(StartProcess.Initing)}"); } if (Process > StartProcess.Running) { - throw new CodeStandardException($"Unable to {nameof(Terminate)} in-process registration service provider"); + throw new LogicException($"Unable to {nameof(Terminate)} in-process registration service provider"); } var skipped = Dispatch(new RegisterProviderEventArgs(provider, this)) @@ -342,7 +342,7 @@ protected override void GuardConstruct(string method) { if (registering) { - throw new CodeStandardException( + throw new LogicException( $"It is not allowed to make services or dependency injection in the {nameof(Register)} process, method:{method}"); } diff --git a/src/CatLib.Core/Container/Container.cs b/src/CatLib.Core/Container/Container.cs index e50d536..df03f80 100644 --- a/src/CatLib.Core/Container/Container.cs +++ b/src/CatLib.Core/Container/Container.cs @@ -336,7 +336,7 @@ public IContainer Alias(string alias, string service) if (!bindings.ContainsKey(service) && !instances.ContainsKey(service)) { - throw new CodeStandardException( + throw new LogicException( $"You must {nameof(Bind)}() or {nameof(Instance)}() serivce before and you be able to called {nameof(Alias)}()."); } @@ -588,7 +588,7 @@ public object Instance(string service, object instance) && instancesReverse.TryGetValue(instance, out string realService) && realService != service) { - throw new CodeStandardException($"The instance has been registered as a singleton in {realService}"); + throw new LogicException($"The instance has been registered as a singleton in {realService}"); } var isResolved = IsResolved(service); @@ -715,7 +715,7 @@ public IContainer OnRebound(string service, Action callback) if (!IsResolved(service) && !CanMake(service)) { - throw new CodeStandardException( + throw new LogicException( $"If you want use Rebound(Watch) , please {nameof(Bind)} or {nameof(Instance)} service first."); } @@ -1566,7 +1566,7 @@ protected virtual void GuardServiceName(string service) { if (service.IndexOf(c) >= 0) { - throw new CodeStandardException( + throw new LogicException( $"Service name {service} contains disabled characters : {c}. please use Alias replacement"); } } @@ -1720,7 +1720,7 @@ private void GuardFlushing() { if (flushing) { - throw new CodeStandardException("Container is flushing can not do it"); + throw new LogicException("Container is flushing can not do it"); } } diff --git a/src/CatLib.Core/Support/Exception/CodeStandardException.cs b/src/CatLib.Core/Support/Exception/CodeStandardException.cs deleted file mode 100644 index 78f537a..0000000 --- a/src/CatLib.Core/Support/Exception/CodeStandardException.cs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of the CatLib package. - * - * (c) CatLib - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Document: https://catlib.io/ - */ - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; - -namespace CatLib.Support -{ - /// - /// Represents a code specification exception that raises this exception due to incorrect use of the framework. - /// - [ExcludeFromCodeCoverage] - public class CodeStandardException : LogicException - { - /// - /// Initializes a new instance of the class. - /// - public CodeStandardException() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - public CodeStandardException(string message) - : base(message) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - /// The inner exception. - public CodeStandardException(string message, Exception innerException) - : base(message, innerException) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected CodeStandardException(SerializationInfo serializationInfo, StreamingContext streamingContext) - : base(serializationInfo, streamingContext) - { - } - } -}