lith 4 年之前
父節點
當前提交
eb2efdecce

+ 6 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/SersLoader/ApiLoader.cs

@@ -259,12 +259,16 @@ namespace Sers.SersLoader
         #endregion
 
 
+        protected virtual ParameterInfo[] MethodInfoGetArgInfos(MethodInfo method)
+        {           
+            return method.GetParameters();
+        }
+
         protected virtual Type MethodInfoGetReturnType(MethodInfo method)
         {
             return method.ReturnType;
         }
 
-
         #region GetApiDesc
         /// <summary>
         /// 
@@ -286,7 +290,7 @@ namespace Sers.SersLoader
             apiDesc.rpcVerify2 = RpcVerify2Loader.GetRpcVerify2FromMethod(method);
 
             //(x.4)ArgType        
-            apiDesc.argType = ssModelBuilder.BuildSsModel_Arg(method, xmlComment);
+            apiDesc.argType = ssModelBuilder.BuildSsModel_Arg(MethodInfoGetArgInfos(method), xmlComment);
 
             //(x.5)ReturnType
             apiDesc.returnType = ssModelBuilder.BuildSsModel_Return(method, MethodInfoGetReturnType(method));

+ 14 - 17
dotnet/Library/Sers/Sers.Core/Sers.Core/SersLoader/SsModelBuilder.cs

@@ -56,16 +56,15 @@ namespace Sers.SersLoader
         }
 
 
-        public SsModel BuildSsModel_Arg(MethodInfo method, MethodComment comment)
+        public SsModel BuildSsModel_Arg(ParameterInfo[] argInfos, MethodComment comment)
         {
-            ParameterInfo[] infos = method.GetParameters();
 
             SsModel model = new SsModel();
 
             //构建 OnDeserialize
 
             #region (x.x.1) 空参数 没有参数
-            if (null == infos || 0 == infos.Length)
+            if (null == argInfos || 0 == argInfos.Length)
             {
                 model.OnDeserialize = (strValue) =>
                 {
@@ -80,13 +79,13 @@ namespace Sers.SersLoader
             // 1)第一个参数有 SsArgEntityAttribute 特性
             // 2)参数个数为1,且(mode 为 object 或者 array),且没有SsArgPropertyAttribute特性
             if (
-                null != infos[0].GetCustomAttribute<SsArgEntityAttribute>() ||
-                (1 == infos.Length && !infos[0].ParameterType.TypeIsValueTypeOrStringType() && null == infos[0].GetCustomAttribute<SsArgPropertyAttribute>())
+                null != argInfos[0].GetCustomAttribute<SsArgEntityAttribute>() ||
+                (1 == argInfos.Length && !argInfos[0].ParameterType.TypeIsValueTypeOrStringType() && null == argInfos[0].GetCustomAttribute<SsArgPropertyAttribute>())
             )
             {
                 #region      
-                int argCount = infos.Length;
-                var argType = infos[0].ParameterType;
+                int argCount = argInfos.Length;
+                var argType = argInfos[0].ParameterType;
                 model.OnDeserialize = (bytes) =>
                 {
                     var args = new object[argCount];
@@ -94,7 +93,7 @@ namespace Sers.SersLoader
                     return args;
                 };
 
-                var argDescType = infos[0].GetCustomAttribute<SsTypeAttribute>()?.Value  ?? argType;
+                var argDescType = argInfos[0].GetCustomAttribute<SsTypeAttribute>()?.Value  ?? argType;
 
                 var modelEntitys = new List<SsModelEntity>();
                 var mEntity = CreateEntityByType(argDescType, modelEntitys);
@@ -105,9 +104,9 @@ namespace Sers.SersLoader
                 model.type = mEntity.type;
 
                 {
-                    model.description = infos[0].GetCustomAttribute<SsDescriptionAttribute>()?.Value;
-                    model.example = infos[0].GetCustomAttribute<SsExampleAttribute>()?.Value;
-                    model.defaultValue = infos[0].GetCustomAttribute<SsDefaultValueAttribute>()?.Value;
+                    model.description = argInfos[0].GetCustomAttribute<SsDescriptionAttribute>()?.Value;
+                    model.example = argInfos[0].GetCustomAttribute<SsExampleAttribute>()?.Value;
+                    model.defaultValue = argInfos[0].GetCustomAttribute<SsDefaultValueAttribute>()?.Value;
                 }
                 #endregion
 
@@ -123,11 +122,11 @@ namespace Sers.SersLoader
                 {
                     var jo = bytes.DeserializeFromArraySegmentByte<JObject>();
 
-                    var arg = new object[infos.Length];
+                    var arg = new object[argInfos.Length];
                     if (null != jo)
                     {
                         int i = 0;
-                        foreach (var info in infos)
+                        foreach (var info in argInfos)
                         {
                             arg[i++] = jo[info.Name].Deserialize(info.ParameterType);
                         }
@@ -136,7 +135,7 @@ namespace Sers.SersLoader
                 };
 
                 var models = new List<SsModelEntity>();
-                var mEntity = CreateEntityByParameterInfo(infos, comment, models);
+                var mEntity = CreateEntityByParameterInfo(argInfos, comment, models);
 
                 model.models = models;
                 model.type = mEntity.type;
@@ -144,9 +143,7 @@ namespace Sers.SersLoader
 
             }
             return model;
-            #endregion
-
-         
+            #endregion         
         }
 
 

+ 12 - 1
dotnet/Library/Sers/Sers.Serslot/Sers.Serslot/ApiLoader.cs

@@ -6,6 +6,7 @@ using Sers.SersLoader;
 using Sers.Core.Module.Api.ApiDesc;
 using Sers.Core.Module.Api.LocalApi;
 using Vit.Extensions;
+using Microsoft.AspNetCore.Mvc;
 
 namespace Sers.Serslot
 {
@@ -40,7 +41,17 @@ namespace Sers.Serslot
             return ControllerHelp.Controller_GetRoutePrefixs(type);
         }
 
-
+        protected override ParameterInfo[] MethodInfoGetArgInfos(MethodInfo method)
+        {
+            var argInfos = base.MethodInfoGetArgInfos(method);
+
+            //剔除指定 FromServices 的函数参数
+            if (argInfos != null) 
+            {
+                argInfos = argInfos.AsQueryable().Where(info => info.GetCustomAttribute<FromServicesAttribute>() == null).ToArray();
+            }
+            return argInfos;
+        }
 
         protected override Type MethodInfoGetReturnType(MethodInfo method)
         {