小编Eri*_*fer的帖子

模型 - 视图 - ViewModel模式违反DRY?

我今天读了这篇文章http://dotnetslackers.com/articles/silverlight/Silverlight-3-and-thetheWat-Form-Control-part-I.aspx关于在你拥有的Silverlight应用程序中使用MVVM模式您的域实体和视图特定实体,它们基本上是真实实体对象的子集.这不是明显违反DRY原则吗?如果是这样,你怎么能以一种很好的方式处理它呢?

silverlight dry mvvm

5
推荐指数
1
解决办法
740
查看次数

无法确定条件表达式的类型?

我刚刚遇到这个(编写代码来演示"问题"):

public ICollection<string> CreateCollection(int x)
{
    ICollection<string> collection = x == 0 
                                   ? new List<string>() 
                                   : new LinkedList<string>();
    return collection;
}
Run Code Online (Sandbox Code Playgroud)

编译器抱怨:

Fehler CS0173:Der Typ des bedingten Ausdrucks kann nicht bestimmt werden,weil keine implizite Konvertierung zwischen"System.Collections.Generic.List"und"System.Collections.Generic.LinkedList"erfolgt.

其翻译大致为:

无法确定条件运算符的类型,因为List和LinkedList之间没有隐式转换.

我可以看到为什么编译器抱怨,但是,嘿,来吧.它试图发挥愚蠢.我可以看到两个表达式不是同一类型,而是有一个共同的祖先,作为奖励,左侧的类型也是共同的祖先.我相信编译器也可以看到它.如果左侧被声明为,我可以理解错误var.

我在这里错过了什么?

编辑:

我接受詹姆斯·冈特的解释.也许只是为了说清楚.我可以很好地阅读编译器规范.我想了解原因.为什么有人决定以这种方式编写规范.这种设计背后必然有一个原因.根据詹姆斯的说法,设计原则是"毫无意外".此外,CodeInChaos还解释了如果编译器试图从常见的祖先中推断出类型,您可能遇到的惊喜.

.net c# compiler-construction

5
推荐指数
1
解决办法
2674
查看次数

是什么使一个类成为根据NUnit集合约束的集合?

我有一个实现的类ICollection<SomeConcreteClass>.NUnit集合约束不会将其识别为集合.

例如Assert.That( sut, Has.No.Member( someObjectOfTypeSomeConcreteClass ) );投掷System.ArgumentException : The actual value must be a collection

Assert.That( sut, Is.Empty );失败了sut.

那么什么时候集合是一个集合(根据NUnit)?

堆栈跟踪:

System.ArgumentException : The actual value must be a collection Parametername: actual
at NUnit.Framework.Constraints.CollectionConstraint.Matches(Object actual)
at NUnit.Framework.Constraints.NotConstraint.Matches(Object actual)
    MyTestFile.cs(36,0): at MyAssembly.MyTestFixture.MyTestMethod()
Run Code Online (Sandbox Code Playgroud)

NUnit 2.4.3.0出现上述问题.我刚用2.6尝试过.Is.Empty现在有效,但Has.No.Member仍然失败.它甚至没有打电话Equals()operator ==().它如何比较收集元素?RhinoMocks Arg<MyCollection>.List.Count( Is.Equal( 1 ) )现在也失败了.

结论:
对于NUnit 2.4,集合约束要求将集合的非泛型ICollection实现为集合(可回答原始问题).IEnumerable相等按预期工作.

使用NUnit 2.6(可能还有3.0),IEnumerable即使Equals被覆盖,匹配元素也会检查s的相等性.这就是为什么如果元素IEnumerable本身就是成员约束不起作用的原因.这是一个已知问题(https://bugs.launchpad.net/nunit-3.0/+bug/646786). …

.net c# collections nunit constraints

5
推荐指数
1
解决办法
1033
查看次数

如何配置prometheus kubernetes_sd_configs指定特定主机端口?

我在 GKE 上的不同端口 (11100) 上运行节点导出器,并将 prometheus.yml 配置为使用 kubernetes_sd_configs。但是,服务发现似乎返回带有Kubelet端口 (10250)的节点 IP <node-ip>:10250/metrics。我can\xe2\x80\x99t似乎找到了一种方法来指定使用哪个端口。有任何想法吗?

\n
 - job_name: gke-nodes\n      kubernetes_sd_configs:\n      - role: node\n
Run Code Online (Sandbox Code Playgroud)\n

此外,node-exporter 在 port 中正确运行11100。我通过在内部节点 IP 中执行curl 来验证它<node-ip>:11100/metrics,它的作用就像一个魅力

\n
\n

这是我的节点导出器定义

\n
apiVersion: apps/v1\nkind: DaemonSet\nmetadata:\n  name: node-exporter-ds\n  namespace: monitoring\n  labels:\n    app: node-exporter\n    belongsTo: monitoring\nspec:\n  selector:\n    matchLabels:\n      app: node-exporter\n  template:\n    metadata:\n      labels:\n        app: node-exporter\n    spec:\n      serviceAccountName: monitoring-sa\n      volumes:\n        - name: proc\n          hostPath:\n            path: /proc\n        - name: sys\n          hostPath:\n            path: /sys\n      containers:\n        - name: node-exporter\n          image: …
Run Code Online (Sandbox Code Playgroud)

google-kubernetes-engine prometheus prometheus-node-exporter

5
推荐指数
1
解决办法
4037
查看次数

有关开发opencart付款方式的文档?

在opencart网站上开发自己的支付方式(或任何模块)的信息相当稀少.是否有其他地方有关此主题的更好信息?

documentation payment module payment-gateway opencart

4
推荐指数
1
解决办法
2804
查看次数

将图标放在圆圈内

在此输入图像描述

我正在做一个项目,但是这个项目有一个验证电子邮件页面,我想在这个界面的开头放一个电子邮件图标,但是绕了一圈,我不能?如何在圆圈周围放置图标?

material-ui react-typescript

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

使用Lambda或LINQ将类实例转换或映射到另一个实例的列表?

我有以下两个类:

class MyData {
  public List<string> PropertyList { get; private set;}
  public string PropertyB { get; set; }
  public string PropertyC { get; set; }
}

class MyData2 {
  public string PropertyA { get; set;}
  public string PropertyB { get; set; }
  public string PropertyC { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

如果我有一个MyClass实例,我需要将它转换为MyData2列表.我可以通过循环MyData.PropertyList并缓存其他属性值并将它们插入MyData2列表来实现,如下所示:

string propertyB = myData.PropertyB;
string propertyC = myData.PropertyC;
List<MyData2> myData2List = new List<MyData>();
foreach(string item in myData.PropertyList)
{
  myData2List.Add(new myData2() { item, propertyB, propertyC });
}
Run Code Online (Sandbox Code Playgroud)

不确定是否可以使用LINQ或Lambda表达式的.Net 3.5功能完成此操作?

c# linq lambda

3
推荐指数
1
解决办法
3764
查看次数

如何在Npgsql中将查询的表名作为命令参数提供?

我想提供查询的表名作为命令参数,如下所示:

public class Foo
{
    private const String myTableName = "mytable";

    public void Bar()
    {
        NpgsqlCommand command = new NpgsqlCommand("SELECT * from :tableName", connection);
        command.Parameters.Add(new NpgsqlParameter("tableName", DbType.String));
        command.Parameters[0].Value = myTableName;
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎导致了这个查询:"SELECT * from E'mytable'"导致错误(请注意单引号).

我真的需要为此进行字符串连接吗?从安全角度来看并不重要,因为用户不能更改表名,但创建SQL查询的字符串连接总是让我感到毛骨悚然......

谢谢,埃里克

.net c# sql postgresql npgsql

3
推荐指数
1
解决办法
1555
查看次数

为什么我不能在LINQ to SQL中重用一个函数

为什么下面的LINQ to SQL语句会抛出异常?

我有一个功能

bool TrimAndCompare(string s1, string s2)
{
   return customer.CustomerID.Trim() == customerID.Trim()
}
Run Code Online (Sandbox Code Playgroud)

...我在linq语句中调用上述函数的其他函数

var customers = from customer in _context.Customers
                          where
                              TrimAndCompare(customer.CustomerID, customerID)
                      select customer;
Run Code Online (Sandbox Code Playgroud)

上面的LINQ to SQL statment函数抛出一个异常但是下面没有为什么?

var customers = from customer in _context.Customers
                      where
                            customer.CustomerID.Trim() == customerID.Trim()
                      select customer;
Run Code Online (Sandbox Code Playgroud)

我得到一个'System.NotSupportedException',我尝试访问客户

.net c# linq-to-sql

3
推荐指数
1
解决办法
135
查看次数

从另一个项目导入 .proto 文件

我有几个包含不同 protobuf 文件的合同项目,但是某些消息类型具有相同的消息类型,例如

message user
{
  Address address = 1
}

message Address 
{
  ....
}
Run Code Online (Sandbox Code Playgroud)

我现在创建了一个共享项目并向其中添加了一个 Address.proto 文件,其中仅包含

syntax = "proto3"
option csharp_namespace = "shared.protos"
package AddressPackage
message Address {....}
Run Code Online (Sandbox Code Playgroud)

我的问题是弄清楚如何将其导入到我不同合同项目中的原型中。我已添加共享项目作为参考,但我从那里尝试的所有其他内容都导致错误。

我知道我需要使用import只是还没有弄清楚如何写字符串。

更新

我正在使用 gRPC.tools nuget 并且所有 .proto 文件都设置为 protobuf 编译器

文件结构如下

用户合同项目

  • Protos -- User.proto 共享项目
  • Protos -- Address.proto

两个项目都在它自己的文件夹中,并且这些文件夹彼此相邻。

在它说的共享项目中

<ItemGroup>
  <None Remove="Protos\Address.proto" />
</ItemGroup>

<ItemGroup>
  <Protobuf Include="Protos\Address.proto">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Protobuf>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

并在 user.contract 中说

<ItemGroup>
  <None Remove="Protos\User.proto" />
</ItemGroup>

<ItemGroup>
  <Protobuf Include="Protos\User.proto" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

提前致谢。

c# protocol-buffers protobuf-net

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