小编sbl*_*lom的帖子

c#中typedef或子类化字符串的替代方法

情况

我有一个类在内部处理许多不同类型的文件路径:一些是本地的,一些是远程的; 一些亲戚,一些绝对.

过去,它的许多方法都将它们作为strings 传递给彼此,但是很难跟踪每种方法所期望的确切路径类型.

理想的修复

所以我们基本上是想typedef四种不同的类型string:RemoteRelative,LocalRelative,RemoteAbsolute,和LocalAbsolute.通过这种方式,静态类型检查器可以帮助开发人员确保他们提供并期望string具有正确的语义.

不幸的stringsealed,在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都是我的梦想.但即使是自定义类的方向步骤也会很棒.

c# syntax typedef

14
推荐指数
3
解决办法
1688
查看次数

如何获得Mathematica内置的全局重写规则列表?

据我所知,Mathematica中的一千多个内置重写规则默认填充全局规则表.有没有办法让Mathematica提供这些规则的完整或部分列表?

wolfram-mathematica

12
推荐指数
1
解决办法
388
查看次数

F#中t <'a>和'at之间有什么区别?

F#t<'a>'a tF#之间的含义有什么不同吗?声明之后它们可以互换使用吗?

f#

12
推荐指数
1
解决办法
613
查看次数

我想将Frotz z-machine解释器移植到亚马逊Kindle上.这甚至可能吗?

我希望能够在亚马逊Kindle 2上播放互动小说的作品.为了做到这一点,我需要将Frotz解释器移植到Kindle.到目前为止,我还没有找到任何讨论Kindle应用程序开发的地方.这样的事情存在吗?我在哪里可以找到更多信息?

kindle z-machine

11
推荐指数
3
解决办法
1952
查看次数

你能用十个原语实现任何纯LISP函数吗?(即没有类型谓词)

本网站提出以下声明: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. …

lisp types predicate function clojure

10
推荐指数
1
解决办法
1370
查看次数

9
推荐指数
1
解决办法
1357
查看次数

在C#中只读二维数组

在C#中是否有任何已建立的返回只读二维数组的方法?

我知道ReadOnlyCollection对于一维数组使用是正确的,我很乐意编写自己的包装类来实现一个this[] {get}.但是如果这个轮子已经存在,我不想重新发明轮子.

c# readonly immutability

9
推荐指数
1
解决办法
2557
查看次数

Django JSON ::'dict'对象没有属性'_meta'

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'

django json

8
推荐指数
1
解决办法
2万
查看次数

IronPython"LookupError:未知编码:hex"

当我尝试在IronPython 2.0中 "导入simplejson"(或依赖于它的东西)时,我得到"LookupError:unknown encoding:hex".我该如何工作?

import json ironpython

6
推荐指数
1
解决办法
2557
查看次数

自.Net 2.0以来,.Net IL一直在改变吗?

我之前听说过.Net 3.5对它编译的IL没有任何改变.在考虑了我所知道的所有编译器功能之后,事实上,它确实可以在同一个旧IL中实现,但我找不到官方来源来证实这一说法.这是真的吗?

.net history cil

6
推荐指数
1
解决办法
333
查看次数