我有一个映射到数据库中的字段的类.该类仅关注字段的名称及其相关的.NET类型. 类型可以是string,int,datetime等.
class Foo()
{
string Name { get; set; }
Type FooType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有另一个继承自Foo的类,它为值添加了一个属性.现在我将值存储为对象,并使用switch语句根据基类FooType对值进行装箱.
class FooWithStuff() : Foo
{
object Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法用泛型实现这一点,为值赋予类型安全性?
编辑:我已将关键要求变为粗体.在声明列表时说Foo需要一个类型.如果我对自定义类这样做,我会创建和接口并使用它.但是在这里我使用的是int,string,DateTime等.Int是一个结构,字符串是一个对象,所以Foo <object>对两者都不起作用.
我有两节课:
class Foo
{
public Bar SomeBar { get; set; }
}
class Bar
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个组合在一起的Foos列表:
var someGroup = from f in fooList
orderby f.SomeBar.Name ascending
group f by f.SomeBar.Name into Group
select Group;
Run Code Online (Sandbox Code Playgroud)
如何从someGroup获取不同Bars的列表?
我想在构建过程中完成两件事:
我已经查看了一些资源,并没有什么能够成为这个场景的最佳解决方案.我的大多数搜索围绕着目标的web.config部分,但如果我要这样做,我想同时完成单元测试.
Scott Hanselman发表了一篇文章,关于制作配置文件的多个副本,创建自定义配置,以及使用批处理文件复制web.config,使配置与源对齐.我不喜欢这个解决方案,因为我必须有相同文件的多个版本,并且有可能一个更新而另一个没有.
使用nAnt看起来很有希望.从我收集的内容中,我将使用批处理文件作为构建过程的一部分.使用xml文件中的变量替换文件模板中的{template}变量对我来说似乎非常简单,所以我想我倾向于使用MSBuild.我关心的是环境配置,多个开发人员需要将nant程序集放在同一个位置,因此应将它们检入源代码控制.这对我来说听起来不错.
我跑过CruiseControl,乍一看看起来很有趣,但似乎需要大量的学习.
我意识到这是一个非常雄心勃勃的目标,需要一些努力来纠正,所以我想在选择路径之前做出明智的决定.对于使用测试和文件配置启动和运行自动构建过程最简单,最干净的方法的任何建议都将不胜感激,谢谢.
自2005年Beta 2以来,我一直在使用TFS,安装它,使用它,并在工作中每天使用它.我想用我的家庭项目的源代码控制解决方案,用Visual Studio 2008 Professional编写,我买不起TFS.
合并之后,对我而言最重要的是集成到Visual Studio中,我刚刚习惯于从IDE内部运行源代码控制以立即进行更改.
我做了一些功课,它归结为Git和Subversion.
混帐
颠覆
在某些时候,我可能会尝试两者只是为了扩展我对这个主题的知识,但在那之前我正在寻找一些有效的东西.
我看到一个有趣的情况围绕C#(VS 2008 SP1)中的货币.下面是测试用例的图像:
alt text http://img697.imageshack.us/img697/8500/testcases.png
我期待第五,六和七个案例(我的错误就是没有在输出中对它们进行编号)来将数字四舍五入到一分钱.
这是我的测试代码:
static void Main(string[] args)
{
decimal one = 10.994m;
decimal two = 10.995m;
decimal three = 1.009m;
decimal four = 0.0044m;
decimal five = 0.0045m;
decimal six = 0.0046m;
decimal seven = 0.0049m;
decimal eight = 0.0050m;
Console.WriteLine(one + ": " + one.ToString("C"));
Console.WriteLine(two + ": " + two.ToString("C"));
Console.WriteLine(three + ": " + three.ToString("C"));
Console.WriteLine(four + ": " + four.ToString("C"));
Console.WriteLine(five + ": " + five.ToString("C"));
Console.WriteLine(six + ": " + …Run Code Online (Sandbox Code Playgroud) 这是我的第一个python脚本,请注意.
我把它从Dive Into Python拼凑起来,效果很好.但是,因为它是我的第一个Python脚本,所以我会感谢有关如何使其更好的提示或可能更好地采用Python编程方式的方法.
import os
import shutil
def getSourceDirectory():
"""Get the starting source path of folders/files to backup"""
return "/Users/robert/Music/iTunes/iTunes Media/"
def getDestinationDirectory():
"""Get the starting destination path for backup"""
return "/Users/robert/Desktop/Backup/"
def walkDirectory(source, destination):
"""Walk the path and iterate directories and files"""
sourceList = [os.path.normcase(f)
for f in os.listdir(source)]
destinationList = [os.path.normcase(f)
for f in os.listdir(destination)]
for f in sourceList:
sourceItem = os.path.join(source, f)
destinationItem = os.path.join(destination, f)
if os.path.isfile(sourceItem):
"""ignore system files"""
if f.startswith("."):
continue
if not …Run Code Online (Sandbox Code Playgroud) 我在代码库中遇到了这个方法,并想知道Big O是什么.该方法采用一个平面列表并创建一个树,在它去的时候分配父和子值.
private void AddChildren(Group group, IEnumerable<Group> groups)
{
foreach (var g in groups)
{
if (g.ParentId == group.Id)
{
g.Parent = group;
group.Children.Add(g);
AddChildren(g, groups);
}
}
}
Run Code Online (Sandbox Code Playgroud)
已经有一段时间了,因为我在识别直接的n ^ 2(或更糟)方法之外做了Big O,但我对它的看法是这样的:
只是扔东西,所以我可以看看我是否在球场:
n +(x*n)
其中x是if循环中的匹配数.
关于这实际上是什么的任何想法都会很棒,谢谢.
我们有一个应用程序从 Rails 3.2 升级到 4.0。
3.2版本已经roots覆盖了routes.rb,我将其移植到新语法,但我不太确定如何处理子域约束。
在3.2中:
constraints(SubDomain) do
root to: "companies#index"
...
end
Run Code Online (Sandbox Code Playgroud)
我尝试像其他根路径一样移植它,但看起来非约束根路径上存在冲突。
这是我尝试过的:
constraints(SubDomain) do
get "/", to: "companies#index", as: :root
...
end
Run Code Online (Sandbox Code Playgroud)
和错误:
/Users/blu/.rvm/gems/ruby-2.1.7/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:in
add_route': Invalid route name, already in use: 'root' (ArgumentError) You may have defined two routes with the same name using the:asoption, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created withresources …
我不明白我的模型如何成为WCF服务.当它驻留在客户端上的Astoria部分类允许远程调用执行持久性调用时,它是有意义的,但是WCF服务没有可用于更新数据存储的模型字段的属性.
即使我可以将模型/域对象类的接口分解为单独的程序集,Silverlight项目也不允许我将其添加为引用.
我的ViewModel应该如何包含我的WCF调用?最终WCF将调用在Linq-to-Sql中实现的存储库程序集,但显然这些实体在这种情况下不是我的模型,我的WCF类是什么?
感谢您的任何指导.
另外,我读过的帖子给出了一个参考框架:
https://github.com/wojtekmach/acme_bank/blob/master/apps/bank/lib/bank/model.ex#L10
alias Bank.{
Account,
Customer,
Deposit,
Ledger,
Repo,
Transfer,
Entry
}
Run Code Online (Sandbox Code Playgroud)
没有它,我得到一个Ecto.Queryable not implemented for Foo, the given module does not exist。如何将Ecto查询内容引入模型中?
c# ×4
big-o ×1
elixir ×1
formatting ×1
generics ×1
git ×1
lambda ×1
linq-to-sql ×1
mvvm ×1
nant ×1
prism ×1
python ×1
rounding ×1
silverlight ×1
svn ×1
tfs ×1
unit-testing ×1
wcf ×1