Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在运行时通过反射获得重载?_C#_Linq To Sql_Reflection - Fatal编程技术网

C# 如何在运行时通过反射获得重载?

C# 如何在运行时通过反射获得重载?,c#,linq-to-sql,reflection,C#,Linq To Sql,Reflection,由于我的工作迫使我使用存储过程,而我没有足够长的时间来阻止它,所以我为所有存储过程定制了LiNQ到SQL代码生成。是的,这是对的,我们所有的数据访问都有存储过程,因为我们没有表访问这意味着我们通常会为所有“实体”创建3个类。现在,当我碰壁时,我几乎完成了最新的改变 下面的代码不工作,原因是它正在调用自身,但我需要获得重载。原因是不可能跟踪40个参数,所以我在项目构建时生成一个“动态”类 [Function(Name="dbo.user_insert")] public IList<Proc

由于我的工作迫使我使用存储过程,而我没有足够长的时间来阻止它,所以我为所有存储过程定制了LiNQ到SQL代码生成。是的,这是对的,我们所有的数据访问都有存储过程,因为我们没有表访问这意味着我们通常会为所有“实体”创建3个类。现在,当我碰壁时,我几乎完成了最新的改变

下面的代码不工作,原因是它正在调用自身,但我需要获得重载。原因是不可能跟踪40个参数,所以我在项目构建时生成一个“动态”类

[Function(Name="dbo.user_insert")]
public IList<ProcedureResult> UserInsert(UserInsertObj userInsertObj)
{
    IExecuteResult result = this.ExecuteMethodCall(this, (MethodInfo)MethodInfo.GetCurrentMethod(), 
        userInsertObj.UserId, userInsertObj.ProductId, userInsertObj.FromIp, 
        userInsertObj.CampaignName, userInsertObj.Campaign, userInsertObj.Login, 
        userInsertObj.Password, userInsertObj.Nickname, userInsertObj.Pin, userInsertObj.Language, 
        userInsertObj.Currency, userInsertObj.Country, userInsertObj.Region, userInsertObj.Birthday, 
        userInsertObj.FirstName, userInsertObj.MiddleName, userInsertObj.LastName, 
        userInsertObj.Address1, userInsertObj.Address2, userInsertObj.Address3, userInsertObj.Zip, 
        userInsertObj.City, userInsertObj.Timezone, userInsertObj.Email, userInsertObj.EmailNotify, 
        userInsertObj.Gender, userInsertObj.Phone, userInsertObj.MobileCc, userInsertObj.MobileNr, 
        userInsertObj.MobileModel, userInsertObj.Referral, userInsertObj.GroupId, 
        userInsertObj.StreetNumber, userInsertObj.StreetName);

    return new List<ProcedureResult> 
    { 
        new ProcedureResult
        {
            Name = "userId",
            Value = result.GetParameterValue(0),
            Type = typeof(System.Nullable<System.Int32>) 
        }
    };
}
如何从CurrentMethod获取过载


编辑:澄清我们不允许使用数据库表。

我忘记了linq!在这个特定场景中,我只有两个方法,一个包含1个参数,另一个包含所有其他参数,因此简单的方法(见下文)可以很好地工作:

method.DeclaringType.GetMethods()
    .Where(x => x.Name == "UserInsert" 
           && x.GetParameters().Count() > 1)
    .Single()

似乎是一种使用LinqToSQL调用存储过程的bizare方式,您知道您可以将它们映射到DataContext类上的方法,是吗?@Ben,谢谢!关于你的评论,我已经更新了问题。可能重复
method.DeclaringType.GetMethods()
    .Where(x => x.Name == "UserInsert" 
           && x.GetParameters().Count() > 1)
    .Single()