我需要创建一个负责结果集处理的类,但可能会使用不同的算法来处理结果集.
我知道以下选项:
1)使用策略patern,下面是伪代码:
interface Strategy {
processResultSet(ResultSet rs);
}
class StrategyA implements Strategy {
processResultSet(ResultSet rs);
}
class StrategyB implements Strategy {
processResultSet(ResultSet rs);
}
Run Code Online (Sandbox Code Playgroud)
Context类将包含对Strategy的引用,Client应该通过Strategy创建Context对象的实现,即
class Context {
private Strategy strategy;
public Context(Strategy strategy) {
this.strategy = strategy;
}
public doSomething(rs) {
strategy.processResultSet(rs);
}
Run Code Online (Sandbox Code Playgroud)
问题是我不想将策略对象传递给Context,但我想创建类似StrategyFactory的东西,它将负责创建具体的策略实现.它将客户与战略分开 - 这是一个好的设计吗?
它是战略与工厂的混合还是实际上只是工厂模式?
我真的很奇怪.我已经创建了新的aspx页面,并且没有使用任何自定义逻辑对象(使用visual studio向导创建的所有内容)尝试从sqldatasource创建网格视图.
数据来自存储过程,单个参数具有默认值.当我刷新架构或单击"测试查询"时,我看到结果行和GridViews字段是核心创建的.但是当我运行页面时,没有网格视图(它只是空的 - 当我添加EmptyDataTemplate时会显示它).我添加了自定义(空)函数和DataBind,DataBinded和RowCreted事件,并且只触发了databind和datavound事件(尽管如我所写 - 存储过程及其默认参数返回行和.net可以在设计模式下读取它们)
程序中没有任何"花哨"的东西,我已经多次这样做了没有问题.我已经尝试了另一个在我们的生产环境中工作的存储过程,并且仍然具有相同的emty gridview
这是代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TEST.aspx.cs" Inherits="site.TEST" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AllowSorting="True" OnDataBinding="GridView1_DataBinding" OnDataBound="GridView1_DataBound"
OnRowCreated="GridView1_RowCreated">
<EmptyDataTemplate>
No Data Available
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="myStoredProcedure" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="val1" Name="par1" Type="String" />
<asp:Parameter Name="val2" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和代码隐藏
using System;
using System.Collections; …Run Code Online (Sandbox Code Playgroud) 我的目标是能够在应用程序之间共享配置设置.例如,我希望能够使用WinForm应用程序来设置和保存设置,并让控制台应用程序能够读取这些设置并作为计划任务运行.我尝试的方法是创建一个由Winform应用程序和控制台应用程序引用的SharedSettings类.在这个类中,只有像这样的公共字符串属性.
public class SharedSettings
{
public string URL { get; set; }
public string DestUser { get; set; }
public string RelScript { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我使用以下序列来序列化SharedSettings类的实例
SharedSettings settings = new SharedSettings();
settings.RelScript = this.txtRelScript.Text;
settings.URL = this.txtURL.Text;
settings.DestUser = this.txtDestUser.Text;
XmlSerializer dehydrator = new XmlSerializer(settings.GetType());
System.IO.FileStream fs = new FileStream(this.configFilePath, FileMode.OpenOrCreate);
dehydrator.Serialize(fs, settings);
Run Code Online (Sandbox Code Playgroud)
并将其反序列化并填充表单中的字段
SharedSettings settings = new SharedSettings();
XmlSerializer dehydrator = new XmlSerializer(settings.GetType());
System.IO.FileStream fs = new FileStream(this.configFile, FileMode.Open);
settings = (SharedSettings)dehydrator.Deserialize(fs);
this.txtRelScript.Text = settings.RelScript;
this.txtURL.Text = …Run Code Online (Sandbox Code Playgroud) 我经常发现自己在编写一个新类时,在类中我传递了许多私有方法中的参数.另一方面,我也创建了一些私人成员,并在一种方法中使用它们.
所以我的问题是"你在哪个规则之后创建了一个私有成员,当你不这样做并将变量从私有方法传递给私有方法"时?
你能给我一些简单的提示或提示,以便设计变得更好吗?
为什么这些查询会返回不同的值?第一个返回结果集按预期,但第二个(据我所知,完全相同)不会.有什么想法吗?
1:
declare @c varchar(200)
set @c = 'columnName'
select top 1 *
from myTable
where @c is not null
and len(convert(varchar, @c)) > 0
Run Code Online (Sandbox Code Playgroud)
2:
SELECT top 1 *
FROM myTable
WHERE columnName IS NOT NULL
and len(convert(varchar,columnName)) > 0
Run Code Online (Sandbox Code Playgroud) 我有一个专为iPhone OS 2.x设计的应用程序.
在某些时候我有这个代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//... previous stuff initializing the cell and the identifier
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:myIdentifier] autorelease]; // A
// ... more stuff
}
Run Code Online (Sandbox Code Playgroud)
但由于initWithFrame选择器在3.0中已弃用,我需要使用respondToSelector和performSelector转换此代码......因此...
if ( [cell respondsToSelector:@selector(initWithFrame:)] ) { // iphone 2.0
// [cell performSelector:@selector(initWithFrame:) ... ???? what?
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如果我必须传递两个参数"initWithFrame:CGRectZero"和"reuseIdentifier:myIdentifier",我如何将A上的调用断开到preformSelector调用?
编辑 - 由于fbrereto的消化,我做到了这一点
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:myIdentifier];
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是"performSelector:withObject:withObject"的参数2的不兼容类型.
myIdentifier是这样声明的
static NSString *myIdentifier = @"Normal";
Run Code Online (Sandbox Code Playgroud)
我试图将呼叫改为
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:[NSString stringWithString:myIdentifier]];
Run Code Online (Sandbox Code Playgroud)
没有成功...
另一点是CGRectZero不是一个对象......
如何允许我的一个字符串参数为空字符串?
当我尝试任何东西或单个空格(名称已更改)时,我收到此错误:
无法解析'test.User'(MyNamespace.MyObject)的非可选依赖项.参数'userName'类型'System.String'
我知道这是一个骗局,但无法正确描述搜索.
当你可以通过顺序输入数字来覆盖一组的所有组合时,它叫什么?
例如,考虑集合{1,2,3,4,5},我想用最小数量的移动覆盖所有3位数组合.
1,2,3,4,5,1,3,2 ......将覆盖{1,2,3},{2,3,4},{3,4,5},{4,5,1 },{5,1,3},{1,3,2}等
我有两个IEnumberable<double>清单.
如何使用Linq将一个列表的每个值添加到另一个列表中相同位置的值?
我在SQL Server 2008表中有一列,其中部分字符串被意外重复.
有没有人有一个快速简便的方法来删除尾随重复的子字符串?
例如,
alpha\bravo\charlie\delta\charlie\delta
Run Code Online (Sandbox Code Playgroud)
应该
alpha\bravo\charlie\delta
Run Code Online (Sandbox Code Playgroud)