H chaps,我正在尝试使用ServiceStack.Text进行JSON解析(在我看到的各种基准测试中,它似乎比JSON.Net表现得更好).但我没有得到我期待的结果.我试图反序列化的类看起来像这样:
[DataContract]
public class RpcRequest<T>
{
[JsonProperty("id")]
[DataMember(Name="id")]
public String Id;
[JsonProperty("method")]
[DataMember(Name="method")]
public String Method;
[JsonProperty("params")]
[DataMember(Name="params")]
public T Params;
[JsonIgnore]
[IgnoreDataMember]
public Policy Policy;
}
Run Code Online (Sandbox Code Playgroud)
我正在调用这样的解析器
public static class Json
{
public static T Deserialize<T>(string serialized)
{
return TypeSerializer.DeserializeFromString<T>(serialized);
}
}
...
RpcRequest<Params> myRequeset = Json.Deserialize(packet);
Run Code Online (Sandbox Code Playgroud)
但是我从该调用中获取了一个没有设置值的实例.即Id
,Method
并且Params
均为空.我正确使用此API吗?
我对新的Mysql XMl函数非常兴奋.
现在我终于可以在我的oldschool关系数据库中嵌入类似"面向对象"的文档.
例如,用例考虑使用facebook connect在您的网站上唱歌的用户.您可以使用图形api为用户获取对象,并获取更好的信息.然而,这些信息可能差异很大.某些字段可能已设置也可能未设置,某些字段可能会随时间添加等等.
好吧,如果你只是在非常特殊的领域(例如朋友关系,性别,电影......),你可以将它们投射到你的关系数据库方案中.
但是,使用XMl函数,您可以将整个对象存储在字段中,然后您的不同模型可以使用ExtractValue函数访问数据.您可以立即存储所有内容,而无需担心以后需要什么.
但性能会是什么?
例如,我有一个表有50,000个条目的表,代表用户.我有一个枚举字段,表明"male", "female
"(或其他各种性别在政治上是正确的).
例如,获取所有男性的表现将非常快.
但是类似的东西怎么样WHERE ExtractValue(userdata, '/gender/') = 'male'
?
如果物体变大,性能会如何变化?
我能不能以某种方式将指数放在指定的xpath选择上?
字段类型如何与此功能/性能一起使用.VARCHAR/BLOB?
我需要全文索引吗?
总结一下我的问题:
Mysql XML functins看起来很棒.如果您只想存储在应用程序中进一步获取和分析的结构化数据,我相信它们真的很棒.
但他们将如何在对其进行内部扫描/排序/比较/计算的程序中展开战斗?
Mysql可以取代像CouchDB/Sesame这样的面向文档的数据库吗?
XML函数的收益和权衡是什么?
它们如何以及为什么它们比将各种数据存储为属性的动态应用程序更好/更差?
例如,键/值表,其中xpath为键,值为值,连接到文档实体.
有人做过任何其他经历或者注意到了一些值得一提的东西吗?
我有下一个代码:
private void button_Click(object sender, RoutedEventArgs e)
{
Thread t = new Thread(Process);
t.SetApartmentState(ApartmentState.STA);
t.Name = "ProcessThread";
t.Start();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
string msg = "Really close?";
MessageBoxResult result =
MessageBox.Show(
msg,
"Closing",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.No)
{
e.Cancel = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要在private void Window_Closing中进行代码工作,只有当它知道ProcessThread仍然是Alive/InProgress/running时.
类似于IF(GetThreadByName("ProcessThread").IsAlive == true)..
我怎么用C#写的?
如何为Android用户启用我的phonegap应用程序的缩放?
我尝试自定义"Sample/src/com/phonegap/Sample/Sample.java",但它仍然无法正常工作:
有任何想法吗?
package com.phonegap.Sample;
import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;
import android.webkit.WebSettings;
public class Sample extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
WebSettings ws = super.appView.getSettings();
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
}
}
Run Code Online (Sandbox Code Playgroud) 我知道Visual Studio 2010 Ultimate有一些功能,我通常会本能地这样做,但我的时间表非常紧张.我也安装了Visio 2010并将其集成到VS中,但其逆向工程功能似乎没有做太多,并且必须在每个项目的基础上运行,这里的障碍是解决方案结构,每个持有几个解决方案文件夹众多项目.
我想就如何将C#解决方案逆向工程到依赖关系图,序列图和类图中提出一些建议.
我尝试做这样的事情:
public const List<String> METRICS = new List<String>()
{
SourceFile.LOC,
SourceFile.MCCABE,
SourceFile.NOM,
SourceFile.NOA,
SourceFile.FANOUT,
SourceFile.FANIN,
SourceFile.NOPAR,
SourceFile.NDC,
SourceFile.CALLS
};
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这不起作用:
FileStorer.METRICS' is of type 'System.Collections.Generic.List<string>'. A const field of a reference type other than string can only be initialized with null.
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
我编写了以下代码以使用NSNotificationQueue执行合并.我想发布一个通知,即使事件多次发生.
- (void) test000AsyncTesting
{
[NSRunLoop currentRunLoop];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(async000:) name:@"async000" object:self];
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000" object:self]
postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil];
while (i<2)
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
NSLog(@"Polling...");
i++;
}
}
- (void) async000:(NSNotification*)notification;
{
NSLog(@"NSNotificationQueue");
}
Run Code Online (Sandbox Code Playgroud)
每次调用方法'test000AsyncTesting'时,具有相同名称的通知都会添加到队列中.根据合并的概念,如果队列具有任意数量的通知但具有相同的名称,那么它将仅发布一次.但是当我运行我的代码时,'async000:'被多次调用,这与添加到NSNotificationQueue的通知数完全相同.我认为合并不起作用.
对我来说,在这两种情况下,代码的执行都是相同的:
情况1:[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000"object:self] postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil];
情况2:[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000"object:self] postingStyle:NSPostWhenIdle];
请告诉我的代码中的错误.
在C#中,可以通过几种不同的方式连接字符串:
使用串联运算符:
var newString = "The answer is '" + value + "'.";
Run Code Online (Sandbox Code Playgroud)
使用String.Format
:
var newString = String.Format("The answer is '{0}'.", value);
Run Code Online (Sandbox Code Playgroud)
使用String.Concat
:
var newString = String.Concat("The answer is '", value, "'.");
Run Code Online (Sandbox Code Playgroud)
每种方法的优点/缺点是什么?我应该什么时候比其他人更喜欢?
问题出现是因为开发人员之间的争论.一个从未使用String.Format
的级联-他认为,这是格式化字符串,而不是进行连结,那就是始终不可读,因为该字符串中的项目以错误的顺序表示.其他经常使用String.Format
的级联,因为他认为这使代码更易于阅读,特别是在有几套参与报价.这两个开发人员也使用连接运算符和String.Builder.
有人可以为此发布xml布局代码(看一下链接),真的不能做到这一点......谢谢.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/background" android:layout_gravity="bottom" android:orientation="vertical" android:baselineAligned="false">
<ImageView android:id="@+id/ImageView01" android:layout_width="fill_parent" android:background="@drawable/logo" android:layout_height="wrap_content"></ImageView>
<LinearLayout android:layout_gravity="center_vertical" android:id="@+id/LinearLayout02" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button02" android:layout_gravity="right" android:text="@+id/Button02"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button03" android:text="@+id/Button03"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button01" android:layout_gravity="bottom" android:text="@+id/Button01"></Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×2
android ×2
xml ×2
coalescing ×1
cordova ×1
database ×1
diagramming ×1
iphone ×1
json ×1
layout ×1
mysql ×1
objective-c ×1
oracle ×1
servicestack ×1
string ×1
visio ×1