该Proto3 C#参考包含以下内容:
包装类型字段
proto3 中大多数众所周知的类型不会影响代码生成,但是包装器类型(StringWrapper、Int32Wrapper 等)会更改属性的类型和行为。
所有包装类型对应于C#值类型(的
Int32Wrapper,DoubleWrapper,BoolWrapper等等)被映射到Nullable<T>哪里T是相应的非空类型。例如,类型的字段会生成类型DoubleValue为 的 C# 属性Nullable<double>。类型的字段
StringWrapper或BytesWrapper在类型C#性能结果string和ByteString产生,但与一默认值null,并允许null要被设置为属性值。对于所有包装器类型,重复字段中不允许使用空值,但允许作为映射条目的值。
当试图生成一个.cs从文件.proto文件,如果我试图声明一个字段Int32Wrapper中.proto的文件,protoc.exe抛出有关错误Int32Wrapper不存在。
syntax ="proto3";
package prototest;
import "MessageIdentifier.proto";
message TestMessage {
string messageTest = 1;
fixed64 messageTimestampTicks = 2;
uint32 sequenceNumber = 3;
MessageUniqueID uniqueID = 4;
Int32Wrapper nullableInt = 5; …Run Code Online (Sandbox Code Playgroud) 我有一个从CSV导入的数据表,如下所示:
FirstTimeTaken LatestTimeTaken Market Outcome Odds NumberOfBets VolumeMatched InPlay
03/08/2013 15:30:14 03/08/2013 15:32:28 Over/Under 3.5 Goals Over 3.5 Goals 5 10 118 1
03/08/2013 14:26:40 03/08/2013 14:29:43 Correct Score 0 - 0 7 12 279 1
03/08/2013 15:15:34 03/08/2013 15:27:39 Match Odds Barnsley 110 7 9 1
28/07/2013 16:57:26 29/07/2013 21:35:55 Match Odds Barnsley 3 9 35 0
Run Code Online (Sandbox Code Playgroud)
我不得不以varchar格式导入前两列,因为我在尝试导入为datetime时遇到错误.现在我有一个表中的数据,我需要将列格式从Varchar转换为Datetime.我试过了:
ALTER TABLE #CSVTest_Data
ALTER COLUMN FirstTimeTaken DATETIME
ALTER TABLE #CSVTest_Data
ALTER COLUMN LatestTimeTaken DATETIME
Run Code Online (Sandbox Code Playgroud)
这会导致错误:'将varchar数据类型转换为日期时间数据类型会导致超出范围的值'.我知道删除最后一行数据可以解决问题,所以我怀疑系统认为日期格式是MM/DD/YYYY,而实际上是DD/MM/YYYY.以下查询工作正常:
SELECT convert(VARCHAR(50),FirstTimeTaken,105) from #CSVTest_Data
SELECT convert(VARCHAR(50),LatestTimeTaken,105) …Run Code Online (Sandbox Code Playgroud) 我用这个时:
<Label Grid.Column="2"
Grid.Row="8"
Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
</Label>
Run Code Online (Sandbox Code Playgroud)
它运行得很好.
但是当我添加Style标签时:
<Label Grid.Column="2"
Grid.Row="8"
Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
<Style>
<Setter Property="Label.Margin" Value="0" />
</Style>
</Label>
Run Code Online (Sandbox Code Playgroud)
它没有编译说:
属性"内容"设置不止一次
我有一个通用类:
public class Foo<T> where T: Interface
{
}
Run Code Online (Sandbox Code Playgroud)
T被强制实现的接口有2个静态方法.
在构造函数中,我希望能够基本上执行以下操作:
public Foo()
{
value1 = T.staticmethod1();
value2 = T.staticmethod2();
}
Run Code Online (Sandbox Code Playgroud)
使用我上面发布的伪代码无法实现这一点.是不是可以用这种方式调用这些静态方法?
我有一个使用c#.net图表控件制作的条形图,如下所示:

如您所见,图表上的每对红色和蓝色条之间都有一个空格.有没有办法删除这些空格?
提前致谢!
编辑:
以下是设计师的作品
chartArea1.Name = "ChartArea1";
this.CHRT_DPS_HPS.ChartAreas.Add(chartArea1);
legend1.Name = "Legend1";
this.CHRT_DPS_HPS.Legends.Add(legend1);
this.CHRT_DPS_HPS.Location = new System.Drawing.Point(3, 271);
this.CHRT_DPS_HPS.Name = "CHRT_DPS_HPS";
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
series1.Color = System.Drawing.Color.Red;
series1.Legend = "Legend1";
series1.MarkerBorderWidth = 0;
series1.Name = "DPS";
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series2.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
series2.Legend = "Legend1";
series2.MarkerBorderWidth = 0;
series2.Name = "HPS";
series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
this.CHRT_DPS_HPS.Series.Add(series1);
this.CHRT_DPS_HPS.Series.Add(series2);
this.CHRT_DPS_HPS.Size = new System.Drawing.Size(1199, 300);
this.CHRT_DPS_HPS.TabIndex = 1;
this.CHRT_DPS_HPS.Text = "CHRT_DPS_HPS";
title1.Name …Run Code Online (Sandbox Code Playgroud) 我有一个工作表,其中包含开始日期和结束日期.我需要获得这些日期之间的月数.我使用公式=MONTH(B1)-MONTH(A1)得到#.但是,当我的日期跨越多年时,此公式失败 - 如果开始日期是2014年1月1日,结束日期是2015年1月1日,那么当我想得到"12"时它返回"1".
然后DATEDIF(A1,B1,"m"),我尝试在日期之间获得#月份,这是有效的.但是,我的问题可以通过以下示例进行总结:
开课日期:2014年1月5日
截止日期:2014年3月1日
"MonthDif":2
DateDif:1
开课日期:2014年1月5日
结束日期:2014年3月10日
"MonthDif":2
DateDif:2
正如您所看到的,该DATEDIF函数返回完整月份month - month的数量,而我的函数返回"占用"的月数,它们是开始日期和结束日期之间的差异,无论它们是否完整.
在任何日期,我都需要几个月,无论是否整整几个月!基本上,我需要确切的MONTH(B1)-MONTH(A1)回报,除了它将在多年内工作.
此外,我正在考虑设计一个自定义VBA功能来实现上述目标.如果有人有任何建议.
我有一个界面IMyInterface,我在使用moq进行单元测试时嘲笑.
Mock<IMyInterface> firstMockedObject = new Mock<IMyInterface>();
Mock<IMyInterface> secondMockedObject = new Mock<IMyInterface>();
Run Code Online (Sandbox Code Playgroud)
被测单元有一个寄存器方法,如下所示:
public void RegisterHandler(Type type, IHandler handler)
然后是一个句柄方法:
public void Handle(IMyInterface objectToHandle)
我试图测试的是,我可以为2种不同的实现设置2个处理程序,IMyInterface并且Handle方法正确地选择使用哪个:
UnitUnderTest.RegisterHAndler(firstMockedObject.Object.GetType(), handler1);
UnitUnderTest.RegisterHAndler(seconMockedObject.Object.GetType(), handler2);
Run Code Online (Sandbox Code Playgroud)
问题是两个模拟对象都属于同一类型.有没有办法迫使Moq生成与不同类型相同接口的2个模拟?
我有一个接口和一个类型化的工厂接口:
public interface ITransientItem : IDisposable
{
void DoWork(WorkItem item);
}
public interface ITransientItemFactory : IDisposable
{
ITransientItem Create();
void Destroy(ITransientItem item);
}
Run Code Online (Sandbox Code Playgroud)
然后,我有了另一个接口的实现,该接口IDependencyOwner : IDisposable 的实现方式为:
public class DependencyOwner: IDependencyOwner
{
private ITransientItemFactory _factory;
public DependencyOwner(ITransientItemFactory factory)
{
_factory = factory;
}
public void PostWork(WorkItem workItem)
{
ITransientItem item = _factory.Create();
item.DoWork(workItem); //this is done on a seperate thread
_factory.Destroy(item);
}
public void Dispose()
{
//first wait for running items to dispose
//then do disposal stuff
}
} …Run Code Online (Sandbox Code Playgroud) 我在种子方法中使用AddOrUpdate来保持我的权限是最新的,但是,在下面的代码更新现有角色(而不是创建它)的情况下,我创建的任何新权限都没有添加到角色中.我究竟做错了什么?
foreach (KeyValuePair<string, string[]> s in new Dictionary<string, string[]>{
{"Superuser", context.Permissions.Select<Permission, string>(p=>p.Name).ToArray()},
})
{
Role r = new Role();
r.Name = s.Key;
r.Permissions = new List<Permission>();
foreach (string p in s.Value)
r.Permissions.Add(context.Permissions.Where(per => per.Name == p).First());
context.Roles.AddOrUpdate(i => i.Name, r);
}
context.SaveChanges();
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的值绑定:
<textarea class="form-control" placeholder="Comments" rows="10" data-bind="value: $root.GetTabComment($data).Comment, valueUpdate: 'keyup'"></textarea>
Run Code Online (Sandbox Code Playgroud)
我使用的原因keyup是因为我有一个"按键输出"系统设置.这在用户键入时效果很好,但是如果他们通过拼写检查来纠正拼写(使用鼠标点击而根本没有键盘),则绑定将不会更新.
绑定变量Comment声明为:
Comment = ko.observable("").extend({throttle: 1000})
订阅很简单:
Comment.subscribe(function(){
//save code
});
Run Code Online (Sandbox Code Playgroud)
当点击一个按钮时,有什么方法可以强制绑定获取文本区域的当前值吗?
c# ×8
wpf ×2
.net ×1
constraints ×1
datetime ×1
excel ×1
function ×1
generics ×1
knockout-2.0 ×1
knockout.js ×1
mocking ×1
moq ×1
mschart ×1
sql ×1
sql-server ×1
static ×1
unit-testing ×1
vba ×1
winforms ×1