我已经阅读了关于此的文档,我想我明白了.一个AutoResetEvent当代码经过复位event.WaitOne(),但ManualResetEvent没有.
它是否正确?
LINQ to SQL中的经典事务模式有什么区别:
using(var context = Domain.Instance.GetContext())
{
try
{
context.Connection.Open();
context.Transaction = context.Connection.BeginTransaction();
/*code*/
context.Transaction.Commit();
}
catch
{
context.Transaction.Rollback();
}
}
Run Code Online (Sandbox Code Playgroud)
vs TransactionScope对象
using (var context = Domain.Instance.GetContext())
using (var scope = new TransactionScope())
{
try
{
/*code*/
scope.Complete();
}
catch
{
}
}
Run Code Online (Sandbox Code Playgroud) 在C#中你应该有如下代码:
public static string importantRegex = "magic!";
public void F1(){
//code
if(Regex.IsMatch(importantRegex)){
//codez in here.
}
//more code
}
public void main(){
F1();
/*
some stuff happens......
*/
F1();
}
Run Code Online (Sandbox Code Playgroud)
或者你应该坚持包含重要模式的正则表达式的实例?使用Regex.IsMatch的成本是多少?我想在每个正则表达式中都会创建一个NFA.根据我的理解,这个NFA的创作并非无足轻重.
我正在编写一些扩展来模仿地图并减少Lisp中的函数.
public delegate R ReduceFunction<T,R>(T t, R previous);
public delegate void TransformFunction<T>(T t, params object[] args);
public static R Reduce<T,R>(this List<T> list, ReduceFunction<T,R> r, R initial)
{
var aggregate = initial;
foreach(var t in list)
aggregate = r(t,aggregate);
return aggregate;
}
public static void Transform<T>(this List<T> list, TransformFunction<T> f, params object [] args)
{
foreach(var t in list)
f(t,args);
}
Run Code Online (Sandbox Code Playgroud)
转换功能将减少如下:
foreach(var t in list)
if(conditions && moreconditions)
//do work etc
Run Code Online (Sandbox Code Playgroud)
这有意义吗?会更好吗?
XPO是我公司选择的对象关系映射器.有关利弊的任何想法?
我只是在寻找关于该产品的一般感觉和轶事.我们没有转向XPO.我们正在摆脱存在于应用程序中的硬编码sql字符串,并完全移动到ORM以进行所有数据访问.
有哪些工具可以自动点击Windows窗体应用程序?这甚至有用吗?我看到我公司的测试人员做了很多这样做,这似乎是浪费时间.
例如
foo() //Some operation bound by an external resource. db,I/O, whatever.
Run Code Online (Sandbox Code Playgroud)
与
var watch = new Stopwatch();
watch.Start();
foo()
var time = watch.ElapsedMilliseconds
watch.Stop();
Run Code Online (Sandbox Code Playgroud) 在os x上使用IntelliJ 11.1的默认emacs键绑定我尝试使用MB(或字面上的选项-B)返回一个单词,而不是向后移动一个单词,输入unicode整数符号.MB(选项-B)在我的emacs安装中正常工作.
假设我在 API Gateway 中有一个类似 /foo/{bar} 的资源。我想通过集成请求模板将请求路径转换为 /bing/baz/{bar} 。
\n\n通过以下方式将“bar”设置到请求正文中非常简单:
\n\n{ "bar": "$inputs.params(\'bar\')" }\nRun Code Online (Sandbox Code Playgroud)\n\n如何在请求时重写目标路径?
\n\n解决方案在“请求响应示例”中有所暗示:
\n\n\n\n但文档没有准确概述“使用输入模板:”的功能。
\n\nResource: /things/{id}\n\nWith input template:\n{\n "id" : "$input.params(\'id\')",\n "count" : "$input.path(\xe2\x80\x98$.things\').size()",\n "things" : $input.json(\xe2\x80\x98$.things\')\n}\nRun Code Online (Sandbox Code Playgroud)\n 我想每个人都看过如下代码:
public void Server2ClientEnumConvert( ServerEnum server)
{
switch(server)
{
case ServerEnum.One:
return ClientEnum.ABC
//And so on.
Run Code Online (Sandbox Code Playgroud)
而不是这种不好,我们可以这样做:
public enum ServerEnum
{
[Enum2Enum(ClientEnum.ABC)]
One,
}
Run Code Online (Sandbox Code Playgroud)
现在我们可以使用反射来翻录ServerEnum并从枚举声明本身获取转换映射.
我在这里遇到的问题是在Enum2Enum属性的声明中.
这有效,但用Enum e替换对象o则不行.我不希望能够将对象传递给构造函数,只传递给其他枚举.
public class EnumToEnumAttribute : Attribute
{
public EnumToEnumAttribute(object o){}
}
Run Code Online (Sandbox Code Playgroud)
这无法编译.
public class EnumToEnumAttribute : Attribute
{
public EnumToEnumAttribute(Enum e){}
}
Run Code Online (Sandbox Code Playgroud)
是否有编译错误的原因?我还能如何传递地图所需的信息:
EnumtoEnumAttribute(Type dest, string enumString)
Run Code Online (Sandbox Code Playgroud)
这似乎太冗长,但如果这是唯一的方法,那么我想我会用它.
Regex.IsMatch( "foo", "[\U00010000-\U0010FFFF]" )
Run Code Online (Sandbox Code Playgroud)
抛出:System.ArgumentException:以相反的顺序解析"[ - ]" - [xy]范围.
查看\ U00010000和\ U0010FFF的十六进制值,我得到:第一个字符为0xd800 0xdc00,第二个字符为0xdbff 0xdfff.
所以我想我确实有一个问题.为什么用\ U形成的Unicode字符在字符串中分成两个字符?
每个人都记得谷歌浏览器同步吗?我以为很好.不幸的是,谷歌决定不将服务升级到Firefox 3.0.Mozilla正在开发谷歌浏览器同步的替代品,这将成为Weave项目的一部分.我尝试过使用Weave,发现它非常慢或完全无法操作.当然,他们现在处于早期开发阶段,所以我不能抱怨.
这个浏览器同步的具体问题让我思考.你们所有人都会想到Mozilla或制作服务器/客户端软件包的人,我们这些用户可以在你的"主"机器上运行吗?现在,您只需知道自己的IP或有办法在工作或任何地方向您的客户端浏览器宣布它.
我可以想到几个问题:非静态IP,在本地comp上打开端口等.似乎Mozilla似乎不想处理许多人同步浏览器所产生的流量.由于所有上传的数据都必须加密,因此他们无法通过此流量获利.
让我们说你有一些资源清理如下:这是C#.
try{/*stuff*/}
catch(Exception e) {/*rollback logs etc.*/}
finally{
if( context.Transaction != null )
context.Transaction.Dispose();
context.Connection.Close();
context.Connection.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
相反,这样做会更强大吗?
try{/*stuff*/}
catch(Exception e) {/*rollback logs etc.*/}
finally{
try{
if( context.Transaction != null )
context.Transaction.Dispose();
}catch(Exception e){/*logs*/}
finally{
context.Connection.Close();
context.Connection.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
这样,如果transaction.dispose在leat处设置为失败,则连接将有机会关闭.
c# ×9
.net ×2
regex ×2
unicode ×2
astral-plane ×1
attributes ×1
automation ×1
browser ×1
devexpress ×1
emacs ×1
enums ×1
exception ×1
firefox ×1
linq ×1
linq-to-sql ×1
macos ×1
optimization ×1
orm ×1
performance ×1
reflection ×1
stopwatch ×1
testing ×1
transactions ×1
windows ×1
xpo ×1