情况
我有一个类在内部处理许多不同类型的文件路径:一些是本地的,一些是远程的; 一些亲戚,一些绝对.
过去,它的许多方法都将它们作为strings 传递给彼此,但是很难跟踪每种方法所期望的确切路径类型.
理想的修复
所以我们基本上是想typedef四种不同的类型string:RemoteRelative,LocalRelative,RemoteAbsolute,和LocalAbsolute.通过这种方式,静态类型检查器可以帮助开发人员确保他们提供并期望string具有正确的语义.
不幸的string是sealed,在BCL中,所以我们不能通过简单的继承来做到这一点.而且没有简单的typedef,所以我们也不能这样做.
实际修复
我最终创建了四个不同的简单类,每个类都包含一个readonly string.
public struct LocalAbsolutePath {
    public readonly string path;
    public LocalAbsolutePath(string path) {
        this.path = path;
    }
}
Run Code Online (Sandbox Code Playgroud)
这大部分都有效,但最终会增加一些不受欢迎的冗长.
问题:我是否忽略了任何自然适合简单C#语法的替代方案?
就像我上面提到的,C风格typedef string LocalAbsolutePath;甚至是F#风格type LocalAbsolutePath = string都是我的梦想.但即使是自定义类的方向步骤也会很棒.
据我所知,Mathematica中的一千多个内置重写规则默认填充全局规则表.有没有办法让Mathematica提供这些规则的完整或部分列表?
我希望能够在亚马逊Kindle 2上播放互动小说的作品.为了做到这一点,我需要将Frotz解释器移植到Kindle.到目前为止,我还没有找到任何讨论Kindle应用程序开发的地方.这样的事情存在吗?我在哪里可以找到更多信息?
本网站提出以下声明:http: //hyperpolyglot.wikidot.com/lisp#ten-primitives
McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, these are the only functions which need to be implemented in a lower language. The way the non-primitives of lisp can be constructed from primitives is analogous to the way theorems can be proven from axioms in mathematics. …
如何在使用HttpWebRequest时限制带宽的使用?
在C#中是否有任何已建立的返回只读二维数组的方法?
我知道ReadOnlyCollection对于一维数组使用是正确的,我很乐意编写自己的包装类来实现一个this[] {get}.但是如果这个轮子已经存在,我不想重新发明轮子.
def display_home(request):
    from datetime import *
    now=datetime.today()
    print 'Month is %s'%now.month
events=Event.objects.filter(e_date__year=datetime.today().year).filter(e_date__month=datetime.today().month,e_status=1).values('e_name','e_date')
return render_to_response("SecureVirtualElection/home.html",{'events': serializers.serialize("json",events, fields=('e_name','e_date'))},context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
error ::'dict'对象没有属性'_meta'
当我尝试在IronPython 2.0中 "导入simplejson"(或依赖于它的东西)时,我得到"LookupError:unknown encoding:hex".我该如何工作?
我之前听说过.Net 3.5对它编译的IL没有任何改变.在考虑了我所知道的所有编译器功能之后,事实上,它确实可以在同一个旧IL中实现,但我找不到官方来源来证实这一说法.这是真的吗?