我不认为这是可能的,但这里......
我想添加可以处理泛型的数字的方法.例如 :
bool<T> MyMethod() where T: Isomething
{
}
Run Code Online (Sandbox Code Playgroud)
将适用于一种类型
bool<T,K> MyMethod() where T: Isomething
{
}
Run Code Online (Sandbox Code Playgroud)
将适用于两种类型
有没有办法处理n种类型 - 例如
bool<T[]> MyMethod() where T: Isomething
{
}
Run Code Online (Sandbox Code Playgroud)
我想要这样做的原因是实现一个静态的nhibernate辅助方法,它可以从多个程序集加载 - 现在它适用于一个程序集.我目前的方法如下所示:
public static ISessionFactory GetMySqlSessionFactory<T>(string connectionString, bool BuildSchema)
{
//configuring is meant to be costly so just do it once for each db and store statically
if (!AllFactories.ContainsKey(connectionString))
{
var configuration =
Fluently.Configure()
.Database(MySQLConfiguration.Standard
.ConnectionString(connectionString)
.ShowSql() //for development/debug only..
.UseOuterJoin()
.QuerySubstitutions("true 1, false 0, yes 'Y', no 'N'"))
.Mappings(m …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我在RichTextBox其中定制了多种类型的应用程序(RichTextBox,RichAlexBox,TransparentRichTextBox).
我想创建一个方法来接受所有这些类型加上一些其他参数.
private void ChangeFontStyle(RichTextBox,RichAlexBox,TransparentRichTextBox rch,
FontStyle style, bool add)
{
//Doing somthing with rch.Rtf
}
Run Code Online (Sandbox Code Playgroud)
我已经通过计算器搜查,发现了一些答案这样,我无法弄清楚如何使用它们来解决我的问题
void foo<TOne, TTwo>() //There's just one parameter here
where TOne : BaseOne //and I can't figure out how to define my other two parameters
where TTwo : BaseTwo
Run Code Online (Sandbox Code Playgroud)
我也试过重载,因为这个答案提供,
private void ChangeFontStyle(TransparentRichTextBox rch, FontStyle style, bool add);
private void ChangeFontStyle(RichAlexBox rch, FontStyle style, bool add);
private void ChangeFontStyle(RichTextBox rch,FontStyle style, bool add)
{
//Some codes …Run Code Online (Sandbox Code Playgroud)