我想同步调用webBrowser.Navigate(string urlString)webBrowser是Windows窗体控件.我是这样做的
...
private delegate void NavigateDelegate(string s);
...
private void Function()
{
NavigateDelegate navigateDelegate =
new NavigateDelegate(this.webBrowser1.Navigate);
IAsyncResult asyncResult =
navigateDelegate.BeginInvoke("http://google.com", null, null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(10);
}
MessageBox.Show("Operation has completed !");
}
Run Code Online (Sandbox Code Playgroud)
但信息永远不会被推.为什么这段代码不能正常工作?
我想使用SSL连接到我的本地SQL Server 2008数据库.
我没有在服务器上安装任何证书,因为根据这个http://msdn.microsoft.com/en-us/library/ms189067.aspx
如果未安装可信证书,SQL Server将在启动实例时生成自签名证书,并使用自签名证书加密凭据.
这是简单的代码
SqlConnection connection =
new SqlConnection(@"Data Source=somePC\SqlExpress;Initial Catalog=test;integrated security = sspi;Persist Security Info=True;Encrypt=true;");
SqlCommand command = new SqlCommand("Select count(*) from Employee", connection);
connection.Open();
int employeeCount = (int)command.ExecuteScalar();
connection.Close();`
Run Code Online (Sandbox Code Playgroud)
注意 encrypt=true;
但是有connection.Open()一个异常是用消息引发的
已成功与服务器建立连接,但在登录前握手期间发生错误.(提供者:SSL提供者,错误:0 - 证书链由不受信任的权威机构颁发.)
我可以批准这个自签名证书吗?
我有以下代码
public interface IInterpreter
{
decimal Evaluate(string expression);
}
public class Interpreter : IInterpreter
{
public decimal Evaluate(string expression)
{
if (String.IsNullOrWhiteSpace(expression))
throw new ArgumentException("Parameter " + nameof(expression) + " cannot be empty");
var rpnExpression = ConvertToReversePolishNotation(expression);
return EvaluateReversePolishExpression(rpnExpression);
}
...
}
Run Code Online (Sandbox Code Playgroud)
这个类将评估像"5 + 5*6"或"(3-5)*(2 + 2)+5"这样的表达式
现在我想编写单元测试.这里唯一的公共功能是Evaluate,根据所有推荐,只应该测试这种方法.
问题是我有一种强烈的感觉,即两个ConvertToReversePolishNotation(expression) EvaluateReversePolishExpression(rpnExpression)函数都必须用单元测试来覆盖...如果某个单元测试失败的Evaluate方法,它不会指出我在哪里是bug(在ConvertToRPNExpression方法或EvaluateReversePolishExpression函数中).
所以问题是 - 在这种情况下是否可以为私有函数编写单元测试?
我正在使用新的C#6.0功能String Interpolation来生成SQL语句.
$@"INSERT INTO [dbo].[TableName]([Column1], [Column2]) Values({item.property1}, {item.property2})";
Run Code Online (Sandbox Code Playgroud)
如果属性为null,则生成的SQL如下所示
INSERT INTO [dbo].[TableName]([Column1], [Column2]) Values(,)
Run Code Online (Sandbox Code Playgroud)
这会导致错误.(不正确的SQL).
我需要Null而不是空格.我能以某种方式实现这一目标吗
对不起,问题的标题有点模糊.
假设我们有以下代码
class ReportManager<T> where T : IPrint
{
public void MakePaperCopy(T t)
{
//...
t.Print();
//...
}
}
public interface IPrint
{
void Print();
}
Run Code Online (Sandbox Code Playgroud)
它可以轻松地重新制作为非通用版本.像这样
class ReportManager
{
public void MakePaperCopy(IPrint print)
{
//...
print.Print();
//...
}
}
Run Code Online (Sandbox Code Playgroud)
第一种情况有一些优势吗?似乎没有.
我可以说每个带有单一的通用类where T: ISomeInterface都可以轻松地重新编译为非通用版本,应该这样做是因为它降低了代码的复杂性吗?
考虑夏令时,如何添加小时数?
我们在10月27日有时间班,所以我希望得到19(或21)小时的结果.
我怎样才能做到这一点 ?
var test = new DateTimeOffset(new DateTime(2018, 10, 26, 20, 0, 0));
var test2 = test.AddHours(48);
Run Code Online (Sandbox Code Playgroud) 可能问题很简单,但我只是坚持这个......我有以下XML
<?xml version="1.0" encoding="utf-8"?>
<InfoLinkDocument>
<HAWBUpdate>
<HAWBNumber>41665496563</HAWBNumber>
<HAWBDetails>
<HAWBWeight>2.56</HAWBWeight>
<HAWBWeightUnit>KG</HAWBWeightUnit>
</HAWBDetails>
</HAWBUpdate>
</InfoLinkDocument>
Run Code Online (Sandbox Code Playgroud)
我在我的XSL文件中有以下内容
<xsl:template match="/InfoLinkDocument">
<xsl:for-each select="HAWBUpdate">
<xsl:variable name="HAWBNumber" select="/HAWBNumber" />
<xsl:variable name="HAWBWeight" select="./HAWBDetails/HAWBWeight" />
<xsl:variable name="HAWBWeight2" select="//HAWBDetails/HAWBWeight" />
<xsl:variable name="HAWBWeight3" select="HAWBDetails/HAWBWeight" />
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)
但由于某种原因HAWBWeight,HAWBWeight2并且HAWBWeight3是空的.为什么?在这种情况下XPath应该是什么?
c# ×5
.net ×2
browser ×1
c#-6.0 ×1
expression ×1
generics ×1
sql-server ×1
ssl ×1
time ×1
timezone ×1
unit-testing ×1
xml ×1
xpath ×1
xslt ×1