贝娄是我的代码的简化版本:
public interface IControl<T>
{
T Value { get; }
}
public class BoolControl : IControl<bool>
{
public bool Value
{
get { return true; }
}
}
public class StringControl : IControl<string>
{
public string Value
{
get { return ""; }
}
}
public class ControlFactory
{
public IControl GetControl(string controlType)
{
switch (controlType)
{
case "Bool":
return new BoolControl();
case "String":
return new StringControl();
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
问题出在ControlFactory类的GetControl方法中.因为它返回IControl而我只有IControl <T>这是一个通用接口.我不能提供T,因为在Bool情况下它会bool而在String情况下它将是字符串.
知道我需要做些什么来使它工作?
我真的不能想出用这句话来表达的最好方法,所以我只想举个例子.假设我有一个像这样创建的表:
CREATE VIEW People
AS
SELECT
id, --int
name, --varchar(20)
birthdate --datetime
FROM SomeTable
Run Code Online (Sandbox Code Playgroud)
如果我想将其从视图更改为物理表,是否有任何方法可以创建具有相同布局的表?
换句话说,我想采取该视图并创建一个这样的表:
CREATE TABLE People(
id int,
name varchar(20),
birtdate datetime
)
Run Code Online (Sandbox Code Playgroud)
...但无需手动编写该查询.
这当然是一个人为的例子.视图有很多具有许多不同数据类型的字段,因此很难手工完成.
只是想获得一些关于主键的意见 - 使用身份/序列号或使用HiLo策略(查询高值并增加应用程序本身的低值)会更好吗?
背景:我有一堆字符串,我从数据库中获取,我想返回它们.传统上,它会是这样的:
public List<string> GetStuff(string connectionString)
{
List<string> categoryList = new List<string>();
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
string commandText = "GetStuff";
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
categoryList.Add(sqlDataReader["myImportantColumn"].ToString());
}
}
}
return categoryList;
}
Run Code Online (Sandbox Code Playgroud)
但后来我认为消费者想要遍历这些项目而不关心其他的东西,而且我不想将自己打包到List中,所以如果我返回一个IEnumerable一切都很好/灵活.所以我在想我可以使用"yield return"类型设计来处理这个......就像这样:
public IEnumerable<string> GetStuff(string connectionString)
{
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
string commandText = "GetStuff";
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlConnection.Open();
SqlDataReader sqlDataReader …Run Code Online (Sandbox Code Playgroud) 在IE和FF中,我可以将事件处理程序附加到onBeforeUnload,并通过将字符串传递给事件的属性,用户将看到一个对话框询问他是否要继续"卸载"(关闭窗口或导航).
Safari和Chrome不支持onBeforeUnload,onUnload似乎为时已晚.有没有办法在Safari/Chrome中复制相同的功能?
注意:我不是想让用户保持人质.我知道这是唠叨和不酷.事实上,我的网站竭尽全力让用户自由自在,并在他们回来时将所有内容都放在其位置.但是,我在IFrames中托管其他网站,有时这些决定摆脱我并接管浏览器,这是我想要避免的.
谢谢!
大多数支持SSL/TLS的邮件客户端只需要用户说明是否应启用SSL.用户不必了解显式和隐式SSL及其之间的差异.
那么,邮件客户端如何确定使用哪种类型的SSL?它是基于默认端口号吗?它只是尝试一个然后另一个吗?
Apple提供的一些应用程序在其设置中包含信息/帮助文本.例如,键盘设置屏幕在"."快捷键切换下包含帮助文本"双击空格键将...".
我知道我可以通过添加组页脚在我的应用程序中执行此操作,但是可以通过在我的Settings.bundle中的plist文件中添加一个字段来在设置应用程序中执行此操作吗?
我试图使用导航命令框架WPF WPF应用程序中的页面之间进行导航(桌面,不XBAP或Silverlight).
我相信我已经正确配置了一切,但它无法正常工作.我构建并运行没有错误,我没有在输出窗口中收到任何绑定错误,但我的导航按钮被禁用.
这是示例应用程序的app.xaml:
<Application x:Class="Navigation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="First.xaml">
</Application>
Run Code Online (Sandbox Code Playgroud)
注意StartupUri指向First.xaml.First.xaml是一个页面.WPF自动在NavigationWindow中托管我的页面.这是First.xaml:
<Page x:Class="Navigation.First"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="First">
<Grid>
<Button
CommandParameter="/Second.xaml"
CommandTarget="{Binding RelativeSource=
{RelativeSource
FindAncestor,
AncestorType={x:Type NavigationWindow}}}"
Command="NavigationCommands.GoToPage"
Content="Go!"/>
</Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)
按钮的CommandTarget设置为NavigationWindow.命令是GoToPage,页面是/Second.xaml.我已经尝试将CommandTarget设置为包含的Page,将CommandParameter设置为"Second.xaml"(First.xaml和Second.xaml都在解决方案的根目录中),并且我尝试将CommandTarget留空.我还尝试在NavigationWindow上设置绑定路径到各种与导航相关的公共属性.到目前为止,没有任何工作.
我在这里错过了什么?我真的不想在代码中进行导航.
澄清.
如果我使用超链接而不是使用按钮:
<Grid>
<TextBlock>
<Hyperlink
NavigateUri="Second.xaml">Go!
</Hyperlink>
</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.但是,我的UI要求意味着使用超链接是正确的.我需要一个巨大的脂肪按钮供人们按.这就是我想使用按钮导航的原因.我只是想知道如何让Button提供与Hyperlink在这种情况下相同的能力.
我有一个C#应用程序,必须与32位库链接,还需要使用尽可能多的内存(成像应用程序); 我们在XP64桌面上运行应用程序,因此我们使用WOW64,在Visual Studio for x86中定位构建(并进行editbin /largeaddressaware后期构建).我们遇到了一些问题:
在Visual Studio内置调试器中,我们只能使用2GB的内存(〜1.5gb到应用程序,加上开销)
从命令行运行,应用程序可以看到3GB的内存,但Microsoft文档似乎说我们应该看到4GB.
任何人都可以告诉我如何获得一个WOW64 C#应用程序,以查看该平台应该能够提供的完整4gb吗?
另外,任何人都可以告诉我如何让Visual Studio(VS 2008,也称为VS90)调试器服从该/largeaddressaware位并停止将应用程序内存限制为2gb ?
我在VS80和VS90中看到了相同的行为; .NET Framework 3.5,3.0和2.0之间也没有区别.这是一个简单的C#程序,用于说明问题; 为x86构建editbin /largeaddressaware,然后在内置调试器中运行,而不是从命令行运行,以查看C#可用的内存差异.
namespace MemoryAllocTest
{
class Program
{
static void Main(string[] args)
{
const int allocSize = 1024 * 1024;
List<byte[]> myMem = new List<byte[]>();
UInt64 totalAlloc = 0;
while (true)
{
myMem.Add(new byte[allocSize]);
totalAlloc += allocSize;
Console.WriteLine("{0} allocs: {1}MB total",
myMem.Count, totalAlloc / (1024 * 1024));
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 给出以下HTML片段:
<form id="aspnetForm" onsubmit="alert('On Submit Run!'); return true;">
Run Code Online (Sandbox Code Playgroud)
我需要删除/清除onsubmit事件的处理程序,并使用jQuery或任何其他JavaScript使用方式注册我自己的处理程序.