我想知道是否有办法使用XmlSerializer反序列化具有不同外壳的对象.
让我们说我的目标是
Class A
{
public String Str{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我有以下XML文件,id喜欢反序列化:
<root><StR>Hello</StR></root>
<root><STR>Hello</STR></root>
<root><str>Hello</str></root>
Run Code Online (Sandbox Code Playgroud)
任何建议/想法?也欢迎操纵DOM等方法:)
问候
我正在自动化 Word,所以我想取消所有警报。
Word.Application word = new Word.Application();
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
Run Code Online (Sandbox Code Playgroud)
我使用上面列出的代码,但我不断收到来自 Word 的消息 - 例如,文档已经打开。有没有办法避免这种情况?如何抑制所有这些愚蠢的消息框?
编辑:
考虑所有答案,我想看门狗确实是唯一的选择。糟糕的是,过去几年没有任何变化。
线程可以在没有真正答案的情况下关闭。
我创建了一个自定义的上下文菜单,我在其中更改了所有项目的外观.这些项目包含不同的控件,如组合框和按钮.现在我希望在按下按钮或选择组合框项目时关闭菜单.目前菜单仍然保持打开状态.你能给我一个提示吗?
这是一个简化的代码来显示我做了什么:
<ContextMenu StaysOpen="False">
<MenuItem>
<MenuItem.Template>
<ControlTemplate>
<Grid MinWidth="200">
<Button Command="{Binding SomeWorkingCommandBinding}">OK</Button>
</Grid>
</ControlTemplate>
</MenuItem.Template>
</MenuItem>
</ContextMenu>
Run Code Online (Sandbox Code Playgroud)
如上所述,当我点击OK按钮时,我想关闭菜单.
UPDATE
以下按钮(或任何其他控件)无需使用Blend SDK即可完成此操作:
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ContextMenu.IsOpen)" Storyboard.Target="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}}">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<sys:Boolean>False</sys:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
Run Code Online (Sandbox Code Playgroud) 我使用以下类使用log4net打印出消息:
public class Message
{
public String Text { get; set; }
public int Id { get; set; }
public override string ToString()
{
return Text;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用Logger.Info(MessageInstance),因此log4net只是调用该ToString方法并打印出消息。我也想记录Id消息对象的属性,但是我不知道该如何实现。
我的转换模式与此类似:
<conversionPattern value="%date %-5level %message%newline" />
Run Code Online (Sandbox Code Playgroud)
我尝试添加,%message{Id}但这只会将整个消息打印两次。
有什么建议么?
我再次面临一项非常普遍的任务.我已经解决了几次,但现在我正在寻找一种更" 优雅 "的方式 - 你能提供一些意见吗?
情况:
我有一个方法,我想运行"半异步".换句话说:启动它并等待给定时间x.如果那个方法没有完成("超时"),我想用一些清理程序继续我的代码.
迄今解决方案:
这两个appraochs工作正常,但我想有一个更好的方法4.0.
建议?
我想使用Windows XP将文件夹作为信件挂载.
例如,我想将c:\ MyFolder挂载为M:\
如何实现这一目标?
我创建了一个非常简单的附加属性:
public static class ToolBarEx
{
public static readonly DependencyProperty FocusedExProperty =
DependencyProperty.RegisterAttached(
"FocusedEx", typeof(bool?), typeof(FrameworkElement),
new FrameworkPropertyMetadata(false, FocusedExChanged));
private static void FocusedExChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ToolBar)
{
if (e.NewValue is bool)
{
if ((bool)e.NewValue)
{
(d as ToolBar).Focus();
}
}
}
}
public static bool? GetFocusedEx(DependencyObject obj)
{
return (bool)obj.GetValue(FocusedExProperty);
}
public static void SetFocusedEx(DependencyObject obj, bool? value)
{
obj.SetValue(FocusedExProperty, value);
}
}
Run Code Online (Sandbox Code Playgroud)
在Xaml中设置它可以很好地工作,但是如果我尝试在Style中设置它:
我在运行时收到一个ArguemntNullException(说:"值不能为null.参数名称:property").
我无法弄清楚这里有什么问题.任何提示都是适当的!
我正在使用a WebRequest来阅读HTML网站.服务器似乎正在重定向我的请求.
我的代码类似于以下内容:
String URI = "http://www.foo.com/bar/index.html"
WebRequest req = WebRequest.Create(URI);
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
String returnedContent = sr.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
当我检查returnedContent它的内容包含来自重定向的内容,如"http://www.foo.com/FOO_BAR/index.html".我确信我请求的URL存在,因为它是收到的响应的一部分(作为IFrame).
有没有办法阻止WebResponse重定向并获取所请求的URL的内容?
UPDATE
设置req.AllowAutoRedirect = false导致302 Found状态代码,但不提供实际内容.
更多细节:我要求的网址是http://www.foo.com/bar/index.html我收到的内容http://www.foo.com/FOO_BAR/index.html
响应看起来类似于:
<body>
<div>
<iframe src="/foo/index.html"></iframe>
</div>
</body>
Run Code Online (Sandbox Code Playgroud) c# redirect httpwebrequest httpwebresponse http-status-code-302
Am I stuck or is this a bug or something?
declare @text nvarchar = 'ThisTextContainsPandOtherCharacters'
select charindex(N'P',@text)
Run Code Online (Sandbox Code Playgroud)
Its always zero?
c# ×5
wpf ×2
.net ×1
c#-4.0 ×1
contextmenu ×1
log4net ×1
mount ×1
ms-word ×1
redirect ×1
sql ×1
sql-server ×1
styles ×1
triggers ×1
windows-xp ×1
xaml ×1