是否可以将IEnumerable<KeyValuePair<string,string>>KeyValuePair的aa转换为匿名类型?
Dictionary<string, string> dict= new Dictionary<string, string>();
dict.add("first", "hello");
dict.add("second", "world");
var anonType = new{dict.Keys[0] = dict[0], dict.Keys[1] = dict[1]};
Console.WriteLine(anonType.first);
Console.WriteLine(anonType.second);
********************output*****************
hello
world
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是因为我从web服务中检索一个对象,该对象表示wsdl中不存在的对象.返回的对象仅包含KeyValuePair集合,该集合包含自定义字段及其值.这些自定义字段可以命名为任何内容,因此我无法将xml反序列化方法映射到我将使用的最终对象(其属性必须绑定到网格).
*仅仅因为我使用Dictionary<string,string>并不意味着它绝对是一本字典,我只是用它来说明.真的是它IEnumerable<KeyValuePair<string,string>>
我一直试图想办法做到这一点,但我画了一个空白.这是c#.NET 4.0.
有没有人知道任何允许使用OCUnit测试异步代码的现有库?我正在考虑类似GHAsyncTestCase但是从中传递的东西SenTestCase.
我问,因为如果我找不到任何我将要移植GHAsyncTestCase到OCUnit,但我不想复制其他人已完成的工作.
我现在放弃了这个我一直试图运行的非常简单的测试.我想在我的窗口中添加一个子视图,除了从iPhone的屏幕的一个角落到另一个角落之外什么都没做,然后使用touchesMoved()它应该从最后一个点到当前点画一条线.问题:1.初始线已经不可见了.2.使用Interface Builder时,初始行是可见的,但即使我调用SetNeedsDisplay(),也不会调用drawRect().
这可能不是那么难......有人可以修改下面的代码使它工作吗?
在FinishedLaunching()的main.cs中:
oView = new TestView();
oView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
oView.Frame = new System.Drawing.RectangleF(0, 0, 320, 480);
window.AddSubview(oView);
window.MakeKeyAndVisible ();
Run Code Online (Sandbox Code Playgroud)
TestView.cs:
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
namespace Test
{
public class TestView : UIView
{
public TestView () : base()
{
}
public override void DrawRect (RectangleF area, UIViewPrintFormatter formatter)
{
CGContext oContext = UIGraphics.GetCurrentContext();
oContext.SetStrokeColor(UIColor.Red.CGColor.Components);
oContext.SetLineWidth(3.0f);
this.oLastPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oLastPoint.Y;
this.oCurrentPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oCurrentPoint.Y;
oContext.StrokeLineSegments(new PointF[] {this.oLastPoint, …Run Code Online (Sandbox Code Playgroud) 我在视图控制器的init方法中设置了一个通知观察器,如下所示:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(saveState)
name:UIApplicationWillResignActiveNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
removeObserver:name:object:这个通知的最佳地点在哪里?我现在用我的dealloc方法调用它,但想知道这是否会导致问题.
iphone notifications cocoa-touch objective-c nsnotifications
错误消息:
1064 - 您的SQL语法出错; 查看与您的MySQL服务器版本对应的手册,以便在'values('name','url','address','city','state','zip','phone')附近使用正确的语法,值('name','url'在第3行
创建表:
create table lawyer_info
(firm_name varchar(100) not null,
firm_url varchar(100) not null,
firm_address varchar(100) not null,
firm_city varchar(100) not null,
firm_state varchar(100) not null,
firm_zip varchar(12) not null,
firm_phone varchar(15) not null);
Run Code Online (Sandbox Code Playgroud)
数据:
insert into lawyer_info firm_name,firm_url,firm_address,firm_city,firm_state,firm_zip,firm_phone)
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone'),
values('name','url','address','city','state','zip','phone');
Run Code Online (Sandbox Code Playgroud) 我正在简化我的代码(我喜欢为每个执行的函数编写最少量的行),而且我经常遇到冗长的数据验证过程.所以决定用伪代码编写一个Validate函数:
public static bool Validate(string input, out object output){
// try to parse data
try {
(TypeOf(object)) output = new (TypeOf(object));
output = (TypeOf(object)).Parse(input);
return true;
} catch {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我在我的代码中使用它来验证几个文本框,它看起来很好并且非常易读:
double var1;
Int32 var2;
byte var3;
if (!Validate(txtDouble.text, var1)) return "Error validating a Double";
if (!Validate(txtInt32.text, var2)) return "Error validating a Int32";
if (!Validate(txtByte.text, var3)) return "Error validating a byte";
// else all data is valid, continue
Process(var1, var2, var3)
Run Code Online (Sandbox Code Playgroud)
我可以为每种类型创建一个静态类Validate和重载,但由于我打算在包含Parse方法的类型上使用,在我看来应该有一种实现上述功能的方法...我只是不要知道我在找什么.一个接口不断出现在我的脑海中,但未能实现.
谢谢!
不是很好的标题,但我不知道该命名.
无论如何,我在计算我的游戏中的总帧数(所以我可以计算平均FPS)long int.为了防止游戏持续很长时间,我该怎么做才能确保我的游戏long int不会超过其限制?如果超过限制会发生什么?
谢谢.
我目前正在进入Spring-Roo和Spring-MVC.我有一个相当简单的应用程序,Roo为我生成.它由两个实体组成,记录和汽车,其中记录引用了一辆特殊汽车.
初始设置后,我将其中一个视图更改为使用字段:选择并显示组合框以选择可用的汽车并将其添加到记录中.
<field:select field="car" id="c_de_recordcars_domain_Record_car" items="${cars}" path="/cars" />
Run Code Online (Sandbox Code Playgroud)
这个标签让我很头疼.到目前为止,comboxbox显示所有可用的汽车......但它通过显示所有属性(例如"Car 1 Tue Jan 18 00:00:00 CET 2011 Friver1")来实现.我想要的是组合框只显示名称属性("Car 1").
在标签内,只有"itemValue"-Attribute,但这只会渲染放入request-param的值...我需要像"displayValue"这样的东西,我可以指向用于的java-field显示.
我怎样才能做到这一点?谢谢
Google从它们索引的文本中删除了大多数特殊字符,因此它不适用于许多与故障排除相关的任务,例如查找变量"$ - "在perl中的内容,或者搜索加载了特殊字符的错误输出.
有没有一种在网络上搜索此类内容的好方法?
此问题与以下问题有关:在Google中查找特殊字符
c# ×2
cocoa-touch ×2
iphone ×2
objective-c ×2
.net ×1
c++ ×1
html-select ×1
increment ×1
insert ×1
int ×1
ios ×1
long-integer ×1
mysql ×1
oop ×1
php ×1
spring-roo ×1
validation ×1
xamarin.ios ×1