有没有在.NET BCL Builder模式的例子吗?例子、模式、NET、BCL

2023-09-04 12:39:48 作者:毁妳男神做妳女人

有没有在.NET基础类库充分生成器模式的例子吗?我在找的东西,有一个实际的董事和多个具体的建设者。

Is there an example of the full builder pattern in the .NET base class library? I'm looking for something that has an actual director and multiple concrete builders.

推荐答案

我远离这个领域的专家,但我的认为的是DbCommandBuilder其继承类(OdbcCommandBuilder, OleDbCommandBuilder, SqlCommandBuilder)可能是一个例子...如果它是确定的抽象建设者基类还担任导演的各种具体类委托给他们的基类,然后调用这样的方法(每反射):

I'm far from an expert in this area, but I think that DbCommandBuilder and its inheriting classes (OdbcCommandBuilder, OleDbCommandBuilder, SqlCommandBuilder) might be an example...if it's OK that the abstract builder base class also serves as the director. The various concrete classes delegate to their base class, which then calls methods like these (per Reflector):

private DbCommand BuildDeleteCommand(DataTableMapping mappings, DataRow dataRow)
{
    DbCommand command = this.InitializeCommand(this.DeleteCommand);
    StringBuilder builder = new StringBuilder();
    int parameterCount = 0;
    builder.Append("DELETE FROM ");
    builder.Append(this.QuotedBaseTableName);
    parameterCount = this.BuildWhereClause(
        mappings, dataRow, builder, command, parameterCount, false);
    command.CommandText = builder.ToString();
    RemoveExtraParameters(command, parameterCount);
    this.DeleteCommand = command;
    return command;
}

这符合一些要求,是一个建设者:

This fulfills some of the requirements to be a builder:

抽象生成器类 在具体的建设者班 在各种DbCommandBuilder方法(复杂的多步建设 BuildDeleteCommand BuildInsertCommand BuildUpdateCommand ) 产品(的DbCommand ,由具体类转换为特定的命令类型),这不仅仅是一个SQL字符串更加复杂,因为它有一个超时,命令类型,一个潜在的交易,等等。 abstract builder class concrete builder classes complex multi-step building in the various DbCommandBuilder methods (BuildDeleteCommand, BuildInsertCommand, BuildUpdateCommand) product (DbCommand, cast to a specific command type by the concrete classes) which is more complex than just a SQL string, because it has a timeout, a command type, potentially a transaction, etc.

不过,有没有担任导演一个单独的类;实际上,在 DbCommandBuilder 基类是导演。

But there's not a separate class serving as the director; in effect, the DbCommandBuilder base class is the director.

 
精彩推荐
图片推荐