考虑这个简单的XML文档.这里显示的序列化XML是来自复杂POCO对象的XmlSerializer的结果,该对象的模式我无法控制.
<My_RootNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="">
<id root="2.16.840.1.113883.3.51.1.1.1" extension="someIdentifier" xmlns="urn:hl7-org:v3" />
<creationTime xsi:nil="true" xmlns="urn:hl7-org:v3" />
</My_RootNode>
Run Code Online (Sandbox Code Playgroud)
目标是在id节点上提取扩展属性的值.在这种情况下,我们使用SelectSingleNode方法,并给出一个XPath表达式:
XmlNode idNode = myXmlDoc.SelectSingleNode("/My_RootNode/id");
//idNode is evaluated to null at this point in the debugger!
string msgID = idNode.Attributes.GetNamedItem("extension").Value;
Run Code Online (Sandbox Code Playgroud)
问题是该SelectSingleNode方法为给定的XPath表达式返回null.
问题:关于此XPath查询的正确性的任何想法,或者为什么此方法调用+ XPath表达式将返回空值?也许命名空间是问题的一部分?
考虑Win Phone 7中的XAML TextBox.
<TextBox x:Name="UserNumber" />
Run Code Online (Sandbox Code Playgroud)
这里的目标是当用户按下Enter屏幕键盘上的按钮时,这将启动一些逻辑以刷新屏幕上的内容.
我想专门为此举办一个活动Enter.这可能吗?
Enter每个按键?即一些模拟ASCII 13?
在SQL Server Management Studio中运行以下查询会给出以下错误.
update table_name set is_active = 0 where id = 3
Run Code Online (Sandbox Code Playgroud)
当前命令发生严重错误.结果(如果有的话)应该被丢弃.
我已经在数据库中的其他几个表上尝试了相同的更新语句,它们工作正常.
DBCC CHECKTABLE('table_name');
Run Code Online (Sandbox Code Playgroud)
给
DBCC results for 'table_name'.
There are 13 rows in 1 pages for object "table_name".
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Run Code Online (Sandbox Code Playgroud) 考虑.NET程序集中的方法:
public static string GetSecurityContextUserName()
{
//extract the username from request
string sUser = HttpContext.Current.User.Identity.Name;
//everything after the domain
sUser = sUser.Substring(sUser.IndexOf("\\") + 1).ToLower();
return sUser;
}
Run Code Online (Sandbox Code Playgroud)
我想使用Moq框架从单元测试中调用此方法.该程序集是webforms解决方案的一部分.单元测试看起来像这样,但我错过了Moq代码.
//arrange
string ADAccount = "BUGSBUNNY";
string fullADName = "LOONEYTUNES\BUGSBUNNY";
//act
//need to mock up the HttpContext here somehow -- using Moq.
string foundUserName = MyIdentityBL.GetSecurityContextUserName();
//assert
Assert.AreEqual(foundUserName, ADAccount, true, "Should have been the same User Identity.");
Run Code Online (Sandbox Code Playgroud)
问题:
MyIdentityBL.GetSecurityContextUserName()?在VS 2010中,Silverlight,C#.我有多个.cs文件.在其中一些中,缺少右键单击上下文菜单中的"重构"和"组织使用"(以及其他项目).
他们为什么失踪?他们怎么能被带回来?
我正在摆弄不同的东西,像这样
var a = 1, b = 2;
alert(a + - + - + - + - + - + - + - + b); //alerts -1
Run Code Online (Sandbox Code Playgroud)
我可以删除空格,它仍然可以工作.
a+-+-+-+-+-+-+-+b
Run Code Online (Sandbox Code Playgroud)
然后我试了一下
a + + b
Run Code Online (Sandbox Code Playgroud)
它运行并评估为3,但当我删除空格时,(a++b)它不会运行,并且它有一个警告,上面写着"令人困惑的加号".
在类似的情况下,我可以理解
a+++++b
Run Code Online (Sandbox Code Playgroud)
可以解释为以下任何一种
(a++) + (++b)
(a++) + +(+b)
a + +(+(++b))
a + +(+(+(+b)))
Run Code Online (Sandbox Code Playgroud)
这会令人困惑.
但在这种情况下
a++b
Run Code Online (Sandbox Code Playgroud)
据我所知,唯一有效的解释方法是
a + +b
Run Code Online (Sandbox Code Playgroud)
为什么不起作用a++b?
我以前使用过BeginAccept()和BeginRead(),但与Visual Studio 2012我想利用新的异步的(async,await)功能在我的socket服务器程序.
我该如何完成AcceptAsync和ReceiveAsync功能?
using System.Net;
using System.Net.Sockets;
namespace OfficialServer.Core.Server
{
public abstract class CoreServer
{
private const int ListenLength = 500;
private const int ReceiveTimeOut = 30000;
private const int SendTimeOut = 30000;
private readonly Socket _socket;
protected CoreServer(int port, string ip = "0.0.0.0")
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
_socket.Listen(ListenLength);
_socket.ReceiveTimeout = ReceiveTimeOut;
_socket.SendTimeout = SendTimeOut;
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); …Run Code Online (Sandbox Code Playgroud) 考虑使用查询表示法编写的LINQ表达式:
List<Person> pr = (from p in db.Persons
join e in db.PersonExceptions
on p.ID equals e.PersonID
where e.CreatedOn >= fromDate
orderby e.CreatedOn descending
select p)
.ToList();
Run Code Online (Sandbox Code Playgroud)
问题:如何使用点表示法编写此LINQ表达式?
我目前正在编写一个C#控制台应用程序,它会生成许多指向网站上不同图像的URL,然后使用下载作为字节流WebClient.DownloadDataAsync().
我的问题是,一旦进行了第一次异步调用,控制台应用程序会认为程序已完成并在异步调用返回之前终止.通过使用Console.Read()我可以强制控制台保持打开,但这似乎不是很好的设计.此外,如果用户在进程期间点击进入(当控制台正在等待输入时),程序将终止.
在等待异步调用返回时,是否有更好的方法可以阻止控制台关闭?
编辑:调用是异步的,因为我在下载过程中通过控制台向用户提供状态指示器.
c# ×5
.net-4.5 ×1
asynchronous ×1
javascript ×1
linq ×1
mocking ×1
moq ×1
mysql ×1
silverlight ×1
sockets ×1
sql ×1
sql-server ×1
syntax ×1
t-sql ×1
unit-testing ×1
webclient ×1
xaml ×1
xml ×1
xpath ×1