添加自动映射
This commit is contained in:
@@ -719,7 +719,6 @@
|
||||
<summary>
|
||||
查
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.Del(System.Collections.Generic.List{System.Guid})">
|
||||
|
||||
@@ -57,7 +57,6 @@ namespace Brick.IFServer.Controllers
|
||||
/// <summary>
|
||||
/// <20><>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result<List<StudentListOutput>>> GetLsit()
|
||||
|
||||
Binary file not shown.
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using AutoMapper.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -9,14 +11,32 @@ namespace Yi.Framework.Common.Helper
|
||||
{
|
||||
public class AssemblyHelper
|
||||
{
|
||||
public static List<Type> GetClass(string assemblyFile, string className = null, string spaceName=null)
|
||||
public static List<Type> GetClass(string assemblyFile, string className = null, string spaceName = null)
|
||||
{
|
||||
Assembly assembly = Assembly.Load(assemblyFile);
|
||||
return assembly.GetTypes().Where(m => m.IsClass
|
||||
&& className == null?true:m.Name==className
|
||||
&& spaceName == null ? true :m.Namespace == spaceName
|
||||
return assembly.GetTypes().Where(m => m.IsClass
|
||||
&& className == null ? true : m.Name == className
|
||||
&& spaceName == null ? true : m.Namespace == spaceName
|
||||
).ToList();
|
||||
}
|
||||
|
||||
public static List<Type> GetClassByBaseClassesAndInterfaces(string assemblyFile, Type type)
|
||||
{
|
||||
Assembly assembly = Assembly.Load(assemblyFile);
|
||||
|
||||
List<Type> resList = new List<Type>();
|
||||
|
||||
List<Type> typeList = assembly.GetTypes().Where(m => m.IsClass).ToList();
|
||||
foreach (var t in typeList)
|
||||
{
|
||||
var data = t.BaseClassesAndInterfaces();
|
||||
if (data.Contains(type))
|
||||
{
|
||||
resList.Add(t);
|
||||
}
|
||||
|
||||
}
|
||||
return resList;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public virtual async Task DeleteAsync(IEnumerable<TKey> ids)
|
||||
public virtual Task DeleteAsync(IEnumerable<TKey> ids)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -110,9 +110,9 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
/// <param name="idEntity"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual async Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
|
||||
protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
|
||||
{
|
||||
return;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -15,8 +16,11 @@ namespace Yi.Framework.WebCore.AspNetCoreExtensions
|
||||
public static IServiceCollection AddAutoMapperService(this IServiceCollection services)
|
||||
{
|
||||
//这里会通过反射自动注入的,先临时这样
|
||||
services.AddAutoMapper(typeof(AutoMapperProfile),typeof(StudentProfile));
|
||||
|
||||
|
||||
var profileList = Common.Helper.AssemblyHelper.GetClassByBaseClassesAndInterfaces("Yi.Framework.DTOModel", typeof(Profile));
|
||||
profileList.Add(typeof(AutoMapperProfile));
|
||||
services.AddAutoMapper(profileList.ToArray());
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user