using Newtonsoft.Json.Linq;
using ReZero.SuperAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ReZero.DependencyInjection
{
public class ActivatorHelper
{
///
/// Create an instance of the specified class type.
///
/// The type of the class to create an instance of.
/// Specifies whether to include non-public constructors.
/// The created instance of the class.
internal static object CreateInstance(Type classType, bool nonPublic, Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider)
{
if (classType.GetCustomAttribute()!=null)
{
var p = serviceProvider;
var result= p!.GetService(classType);
var diProperties = classType.GetProperties().Where(it => it.GetCustomAttribute() != null);
foreach (var item in diProperties)
{
item.SetValue(result, p!.GetService(item.PropertyType));
}
return result;
}
else
{
// If the class has no parameters in the constructor, directly instantiate the object
return Activator.CreateInstance(classType, nonPublic);
}
}
}
}