虽然我发现了许多方法来反序列化特定属性,同时阻止它们序列化,但我正在寻找相反的行为.
我发现有很多问题要求反过来:
我可以指示Json.NET反序列化,但不能序列化特定属性吗?
JSON.Net - 仅在序列化时使用JsonIgnoreAttribute(但在反序列化时不使用)
如何序列化特定属性,但阻止它反序列化回POCO?是否有可用于装饰特定属性的属性?
基本上我正在寻找与反序列化的ShouldSerialize*方法相当的方法.
我知道我可以写一个自定义转换器,但这似乎有点矫枉过正.
编辑:
这是一个更多的背景.这背后的原因是我的班级看起来像:
public class Address : IAddress
{
/// <summary>
/// Gets or sets the two character country code
/// </summary>
[JsonProperty("countryCode")]
[Required]
public string CountryCode { get; set; }
/// <summary>
/// Gets or sets the country code, and province or state code delimited by a vertical pipe: <c>US|MI</c>
/// </summary>
[JsonProperty("countryProvinceState")]
public string CountryProvinceState
{
get
{
return string.Format("{0}|{1}", this.CountryCode, this.ProvinceState);
}
set
{
if (!string.IsNullOrWhiteSpace(value) && value.Contains("|")) …
Run Code Online (Sandbox Code Playgroud) 在一个bower.json
文件中,用于什么resolution
和overrides
属性?
{
"name": "name",
"dependencies": {
"angular": "~1.4.8",
...
"jquery": "2.2.4"
},
"overrides": {
"ionic": {
"main": [
"release/js/ionic.js",
"release/js/ionic-angular.js"
]
}
},
"resolutions": {
"angular-ui-router": "~0.2.15",
"angular": "~1.5.3"
}
}
Run Code Online (Sandbox Code Playgroud) 如果我有一个控制台应用程序,其代码如下:
using (DisposableObject object = new DisposableObject())
{
if (a condition)
Environment.Exit(0);
// Do Stuff
}
Run Code Online (Sandbox Code Playgroud)
我的物品会妥善处理吗?或者在清理对象之前线程是否死亡?
从V6.1更新到V8.1后,我们的MVC自定义代码无效,它返回404(自定义代码是一些API使用Sitefinity API读取内容和商业数据).
根据文档" here ",它说"Bootstrapper.MVC.MapRoute已被删除.请调用RouteTable.Routes.MapRoute(System.Web.Mvc)".,所以我改变了我的代码
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Bootstrapper.MVC.MapRoute(
"ExternalAccess",
"baseApi/{controller}/{action}/{id}",
new { controller = "MvcMainApiCntr", action = "Index", id = "" }
);
}
Run Code Online (Sandbox Code Playgroud)
至
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"ExternalAccess",
"baseApi/{controller}/{action}/{id}",
new { controller = "MvcMainApiCntr", action = "Index", id = "" }
);
}
Run Code Online (Sandbox Code Playgroud)
但路由仍然无法正常工作.
以下是我们的MVC类的示例:
using System;
using System.IO;
using System.Net;
using System.Web.Mvc;
using HtmlAgilityPack;
using Telerik.Sitefinity.Abstractions;
namespace SitefinityWebApp.Mvc.Controllers
{
public class SharedAssetsController : Controller
{
[HttpGet]
public ViewResult …
Run Code Online (Sandbox Code Playgroud) 通常,我用C#编写.NET,但是目前我正在更新用VB.NET编写的项目,并注意到For Each
循环中使用了一种奇怪的语法.
两者之间有什么区别吗?
For Each x in collection.Items
...
Next
Run Code Online (Sandbox Code Playgroud)
和
For Each x in collection.Items
...
Next x
Run Code Online (Sandbox Code Playgroud)
?
我在这里的代码中看到了两个并且好奇为什么有人会使用第二个变体.
c# ×3
json ×2
asp.net-mvc ×1
azure ×1
bower ×1
idisposable ×1
json.net ×1
sitefinity ×1
syntax ×1
vb.net ×1