Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CatLib.Core.Tests/Support/Container/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,8 @@ public void TestResloveAttrClassSpeculationServiceAttrs()
});
}

public class VariantModel : IVariant
[Variant]
public class VariantModel
{
public int num;
public VariantModel(int num)
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/Support/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
* Document: https://catlib.io/
*/

using System;

namespace CatLib
{
/// <summary>
/// 可转变的
/// <para>实现该接口的类,允许依赖注入容器将用户传入的基本类型(包含string)转变为目标类</para>
/// A constructor that represents the class allows a primitive type(Include string) to be passed in to be converted to the current class.
/// </summary>
public interface IVariant
[AttributeUsage(AttributeTargets.Class)]
public class VariantAttribute : Attribute
{
}
}