diff --git a/src/CatLib.Core.Tests/Support/Container/ContainerTests.cs b/src/CatLib.Core.Tests/Support/Container/ContainerTests.cs index 02b9fb3..ef854b1 100644 --- a/src/CatLib.Core.Tests/Support/Container/ContainerTests.cs +++ b/src/CatLib.Core.Tests/Support/Container/ContainerTests.cs @@ -1994,7 +1994,8 @@ public void TestResloveAttrClassSpeculationServiceAttrs() }); } - public class VariantModel : IVariant + [Variant] + public class VariantModel { public int num; public VariantModel(int num) diff --git a/src/CatLib.Core/Support/Container/Container.cs b/src/CatLib.Core/Support/Container/Container.cs index 2dd948a..d660000 100644 --- a/src/CatLib.Core/Support/Container/Container.cs +++ b/src/CatLib.Core/Support/Container/Container.cs @@ -865,7 +865,7 @@ protected virtual bool ChangeType(ref object result, Type conversionType) return true; } - if (IsBasicType(result.GetType()) && typeof(IVariant).IsAssignableFrom(conversionType)) + if (IsBasicType(result.GetType()) && conversionType.IsDefined(typeof(VariantAttribute), false)) { try { diff --git a/src/CatLib.Core/Support/Container/IVariant.cs b/src/CatLib.Core/Support/Container/VariantAttribute.cs similarity index 56% rename from src/CatLib.Core/Support/Container/IVariant.cs rename to src/CatLib.Core/Support/Container/VariantAttribute.cs index 1969082..2c61528 100644 --- a/src/CatLib.Core/Support/Container/IVariant.cs +++ b/src/CatLib.Core/Support/Container/VariantAttribute.cs @@ -9,13 +9,15 @@ * Document: https://catlib.io/ */ +using System; + namespace CatLib { /// - /// 可转变的 - /// 实现该接口的类,允许依赖注入容器将用户传入的基本类型(包含string)转变为目标类 + /// A constructor that represents the class allows a primitive type(Include string) to be passed in to be converted to the current class. /// - public interface IVariant + [AttributeUsage(AttributeTargets.Class)] + public class VariantAttribute : Attribute { } }