有没有办法优雅地处理http状态代码422.我在这里寻找最好的做法.我知道HttpStatusCode是一个枚举所以我试过的是这个,
HttpStatusCode Unprocessable = (HttpStatusCode)422;
if (Response == (HttpStatusCode)422)
Run Code Online (Sandbox Code Playgroud)
但是不允许我比较它.我在这里做错了吗?
什么是在运行时添加此状态代码的最佳方法.
在我的应用程序中,我使用newtonsoft来序列化和反序列化对象,我想知道是否有任何内置的API来确定输入字符串是否可以反序列化为特定对象?
public TObject Deserialize<TObject>(string serialized)
{
/// I want check the condition, and if is not serialized string just return default(TObject)
return JsonConvert.DeserializeObject<TObject>(serialized);
}
Run Code Online (Sandbox Code Playgroud)
我不想用try catch.目前我实现了这样,但希望在开始反序列化对象之前找到验证字符串的方法.
我已经看到这个问题以"TryParse"的方式反序列化json,但它不是我的答案,因为我没有任何特定的模式,JSON格式可以动态更改.
在我的项目中,我使用 Servicestack 从特定 URL 获取数据,此过程是可配置的,我在单独的线程中调用获取数据,如果引发超时错误,我想实现重试。我在 JsonServiceClient 上创建了包装类并在那里实现了重试,但我想知道这种方法的最佳解决方案是什么。
var _client = new JsonServiceClient { Timeout = timeout };
var counter = 0;
do
{
try
{
result = _client.Get<TResponse>(url);
break;
}
catch (Exception exp)
{
//Logging exception
}
}
while (++counter < this.Retry);
Run Code Online (Sandbox Code Playgroud) 本代码在WP8.0中工作,但在WP8.1 Universal Apps中我收到了错误.
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
//Some Statements
}
Run Code Online (Sandbox Code Playgroud)
例外
覆盖'protected'继承的成员'Windows.UI.Xaml.FrameworkElement.OnApplyTemplate()时无法更改访问修饰符