我有以下组成部分:
public interface IJob {
ILogger Logger { get; set; }
}
public class JobC : IJob
{
public ILogger Logger { get; set; }
private ServiceA serviceA;
private ServiceB serviceB;
public JobC(ServiceA serviceA, ServiceB serviceB)
{
this.serviceA = serviceA;
this.serviceB = serviceB;
}
}
public class ServiceB
{
public ILogger Logger { get; set; }
}
public class ServiceA
{
public ILogger Logger { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如您所见,到处都有Logger属性。问题是,我需要在解析期间传递该属性值(不同的作业需要不同的配置记录器)。因此,如果只有顶层组件需要它,那么它就像
var childLogger = Logger.CreateChildLogger(jobGroupName);
var job = windsorContainer.Resolve(jobType);
job.Logger = …Run Code Online (Sandbox Code Playgroud) 我在应用程序配置中启用了 System.Net 日志记录,问题是日志文件中的 xml 消息如下所示:
System.Net Verbose: 0 : [7148] 00000000 : 3C 73 3A 45 6E 76 65 6C-6F 70 65 20 78 6D 6C 6E : <s:Envelope xmln
System.Net Verbose: 0 : [7148] 00000010 : 73 3A 73 3D 22 68 74 74-70 3A 2F 2F 73 63 68 65 : s:s="http://sche
Run Code Online (Sandbox Code Playgroud)
这使得它很难阅读(只要我不需要十六进制表示,并且文本表示有几个符号宽)。有没有办法告诉 .net 跳过十六进制部分?
我有一个声明的方法,如下所示:
public void OriginalMethod(Func<object,bool> selector)
Run Code Online (Sandbox Code Playgroud)
我想从泛型方法中调用它,它具有如下声明:
public void GenericMethod<T>(Func<T, bool> selector)
Run Code Online (Sandbox Code Playgroud)
我怎么做?
我有自定义 IClientMessageFormatter,当前将属性添加到消息中指定的 xml 元素:
public class GetOrdersMessageFormatter : IClientMessageFormatter
{
readonly IClientMessageFormatter original;
public GetOrdersMessageFormatter(IClientMessageFormatter actual)
{
original = actual;
}
public void AddArrayNamespace(XmlNode node)
{
if (node != null)
{
var attribute = node.OwnerDocument.CreateAttribute("test");
attribute.Value = "test";
node.Attributes.Append(attribute);
}
}
public object DeserializeReply(Message message, object[] parameters)
{
return original.DeserializeReply(message, parameters);
}
public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
{
Message newMessage = null;
var message = original.SerializeRequest(messageVersion, parameters);
if (message.Headers.Action == "urn:Mage_Api_Model_Server_HandlerAction")
{
var doc = new XmlDocument();
using (var …Run Code Online (Sandbox Code Playgroud) 我有Windows窗体UI,允许我在TextBox中输入字符串格式的格式,如:
输入结果格式: {sku}:{value} \n
问题是,\n正在转义,因此调试视图中的结果格式字符串如下所示:
{sku}:{value} \\n
Run Code Online (Sandbox Code Playgroud)
这会产生\n而不是换行中的换行符.
所以问题是,如何防止这种情况,或者如何在使用之前删除转义 StringBuilder.AppendFormat()
更新:我已经决定从notepad ++窗口添加图片,可能会有助于理解我需要什么以及为什么(尽管我的用例有点不同,我认为想法是一样的):

试图在appharbor上启动我的项目,它失败了:
"D:\ temp\cijsrn4n.1kq\input\TinyBlogMvc4.sln"(默认目标)(1) - >"D:\ temp\cijsrn4n.1kq\input\TinyBlogMvc4\TinyBlogMvc4.csproj"(默认目标)(2) - >(_ CopyWebApplicationLegacy target) - > C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v10.0\WebApplica tions\Microsoft.WebApplication.targets(178,5):错误MSB3021:无法复制文件"obj\Debug\build.force" to"D:\ temp\cijsrn4n.1kq\output_PublishedWebsites\TinyBlogMvc4\_ obj\Debug\build.force".找不到路径'obj\Debug\build.force'的一部分.[D:\ temp\cijsrn4n.1kq\input\TinyBlogMvc4\TinyBlogMvc4.csproj] C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v10.0\WebApplica tions\Microsoft.WebApplication.targets(178,5) :错误MSB3021:无法将文件"obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache"复制到"D:\ temp\cijsrn4n.1kq\output_PublishedWebsites\TinyBlogMvc4\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache".找不到路径'obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache'的一部分.[d:\ TEMP\cijsrn4n.1kq \输入\ TinyBlogMvc4\TinyBlogMvc4.csproj]
0 Warning(s) 2 Error(s)
Run Code Online (Sandbox Code Playgroud)
它建立在我的电脑上很好,任何想法我缺少什么?
.NET Framework版本为4.0
我需要能够模拟IDocumentQuery,以便能够测试查询文档集合并可能使用谓词来过滤它们的代码:
IQueryable<T> documentQuery = client
.CreateDocumentQuery<T>(collectionUri, options);
if (predicate != null)
{
documentQuery = documentQuery.Where(predicate);
}
var list = documentQuery.AsDocumentQuery();
var documents = new List<T>();
while (list.HasMoreResults)
{
documents.AddRange(await list.ExecuteNextAsync<T>());
}
Run Code Online (Sandbox Code Playgroud)
我使用/sf/answers/3493821341/的答案来编写以下方法:
public static IDocumentClient Create<T>(params T[] collectionDocuments)
{
var query = Substitute.For<IFakeDocumentQuery<T>>();
var provider = Substitute.For<IQueryProvider>();
provider
.CreateQuery<T>(Arg.Any<Expression>())
.Returns(x => query);
query.Provider.Returns(provider);
query.ElementType.Returns(collectionDocuments.AsQueryable().ElementType);
query.Expression.Returns(collectionDocuments.AsQueryable().Expression);
query.GetEnumerator().Returns(collectionDocuments.AsQueryable().GetEnumerator());
query.ExecuteNextAsync<T>().Returns(x => new FeedResponse<T>(collectionDocuments));
query.HasMoreResults.Returns(true, false);
var client = Substitute.For<IDocumentClient>();
client
.CreateDocumentQuery<T>(Arg.Any<Uri>(), Arg.Any<FeedOptions>())
.Returns(query);
return client;
}
Run Code Online (Sandbox Code Playgroud)
只要不使用过滤,它就可以正常工作IQueryable.Where。 …
我正在查看使用hadlebars.js的示例,其中模板处理如下所示:
var source = $("#some-template").html();
var template = Handlebars.compile(source);
var data = { users: [
{username: "alan", firstName: "Alan", lastName: "Johnson", email: "alan@test.com" },
{username: "allison", firstName: "Allison", lastName: "House", email: "allison@test.com" },
{username: "ryan", firstName: "Ryan", lastName: "Carson", email: "ryan@test.com" }
]};
$("#content-placeholder").html(template(data));
Run Code Online (Sandbox Code Playgroud)
和模板是:
<tbody>
{{#users}}
<tr>
<td>{{username}}</td>
<td>{{firstName}} {{lastName}}</td>
<td>{{email}}</td>
</tr>
{{/users}}
</tbody>
Run Code Online (Sandbox Code Playgroud)
现在我有来自ASP.NET MVC的JSON结果,我想不出我应该描述我的模板的方式,因为它没有"users"属性,它看起来像:
{[{username: "alan", firstName: "Alan", lastName: "Johnson", email: "alan@test.com" }]}
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式影响JsonResult输出我需要的东西,或者有一种方法来修复模板而不触及控制器代码?
我需要文本块,它可以在全文和修剪文本之间切换,如下图所示:

并且找不到类似的东西。
Expander 与此类似,但默认情况下它会显示修剪后的完整版本(标题中修剪,内容完整)。
我想写一些带有附加属性的东西,但我需要绘制按钮,检查它是否需要按钮(文本没有被修剪),执行折叠和展开逻辑 - 简而言之,我感觉像在这里发明轮子,有人应该以前做过这个,只是我可能找不到它?
据我所知,NServicebus以这种方式工作 - 它使用DTC将所有数据库事务与消息事务一起包装,如果失败,则回滚所有内容.
现在,我不需要,NServicebus会处理我的数据库事务 - 我会自己处理它们 - 因为我不想使用DTC(nservicebushost和sql server在不同的ec2实例上,我认为我无法在ec2实例上打开RPC端口),但我不希望在处理失败的情况下丢失消息 - 如果发生异常,我希望重试并在最大重试后将消息移动到错误队列.
我可以将Nservicebus配置为这样吗?
c# ×7
appharbor ×1
asp.net-mvc ×1
c#-4.0 ×1
debugging ×1
escaping ×1
json ×1
linq ×1
logging ×1
msbuild ×1
nservicebus ×1
nsubstitute ×1
wcf ×1
wpf ×1
xaml ×1