本文整理汇总了C#中TypeNameHandling类的典型用法代码示例。如果您正苦于以下问题:C# TypeNameHandling类的具体用法?C# TypeNameHandling怎么用?C# TypeNameHandling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeNameHandling类属于命名空间,在下文中一共展示了TypeNameHandling类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SaveToFile
public void SaveToFile(object obj, string file, Formatting formatting = Formatting.Indented, TypeNameHandling nameHandling = TypeNameHandling.Auto)
{
var path = Util.Str.getFolder(file);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
File.WriteAllText(file, WriteObjectAsString(obj, formatting, nameHandling));
}
开发者ID:Websilk,项目名称:Home,代码行数:9,代码来源:Serializer.cs
示例2: WriteObjectAsString
public string WriteObjectAsString(object obj, Formatting formatting = Formatting.None, TypeNameHandling nameHandling = TypeNameHandling.Auto)
{
return JsonConvert.SerializeObject(obj, formatting,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
TypeNameHandling = nameHandling
});
}
开发者ID:Websilk,项目名称:Home,代码行数:9,代码来源:Serializer.cs
示例3: JsonSerializer
/// <summary>
/// Initializes a new instance of the <see cref="JsonSerializer"/> class.
/// </summary>
public JsonSerializer()
{
_referenceLoopHandling = JsonSerializerSettings.DefaultReferenceLoopHandling;
_missingMemberHandling = JsonSerializerSettings.DefaultMissingMemberHandling;
_nullValueHandling = JsonSerializerSettings.DefaultNullValueHandling;
_defaultValueHandling = JsonSerializerSettings.DefaultDefaultValueHandling;
_objectCreationHandling = JsonSerializerSettings.DefaultObjectCreationHandling;
_preserveReferencesHandling = JsonSerializerSettings.DefaultPreserveReferencesHandling;
_typeNameHandling = JsonSerializerSettings.DefaultTypeNameHandling;
_binder = DefaultSerializationBinder.Instance;
}
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:14,代码来源:JsonSerializer.cs
示例4: CreateSettings
/// <summary>
/// Creates the settings instance.
/// </summary>
/// <param name="nullValueHandling">The null value handling.</param>
/// <param name="typeNameHandling">The type name handling.</param>
/// <returns></returns>
private static JsonSerializerSettings CreateSettings(NullValueHandling nullValueHandling, TypeNameHandling typeNameHandling) {
var jsonSerializerSettings = new JsonSerializerSettings {
NullValueHandling = nullValueHandling,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
TypeNameHandling = typeNameHandling,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
};
jsonSerializerSettings.Converters.Add(new BeetleDateTimeConverter { DateTimeFormat = "yyyy-MM-dd\\THH:mm:ss.fffK" });
jsonSerializerSettings.Converters.Add(new TimeSpanConverter());
jsonSerializerSettings.Converters.Add(new StringEnumConverter());
jsonSerializerSettings.Converters.Add(new ByteArrayConverter());
jsonSerializerSettings.Converters.Add(new DbGeometryConverter());
jsonSerializerSettings.Converters.Add(new DbGeographyConverter());
return jsonSerializerSettings;
}
开发者ID:amartelr,项目名称:Beetle.js,代码行数:23,代码来源:BeetleConfig.cs
示例5: ShouldWriteType
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
TypeNameHandling resolvedTypeNameHandling =
((member != null) ? member.TypeNameHandling : null)
?? ((containerProperty != null) ? containerProperty.ItemTypeNameHandling : null)
?? ((containerContract != null) ? containerContract.ItemTypeNameHandling : null)
?? Serializer.TypeNameHandling;
if (HasFlag(resolvedTypeNameHandling, typeNameHandlingFlag))
return true;
// instance type and the property's type's contract default type are different (no need to put the type in JSON because the type will be created by default)
if (HasFlag(resolvedTypeNameHandling, TypeNameHandling.Auto))
{
if (member != null)
{
if (contract.UnderlyingType != member.PropertyContract.CreatedType)
return true;
}
else if (containerContract != null && containerContract.ItemContract != null)
{
if (contract.UnderlyingType != containerContract.ItemContract.CreatedType)
return true;
}
}
return false;
}
开发者ID:draptik,项目名称:RepoSync,代码行数:28,代码来源:JsonSerializerInternalWriter.cs
示例6: ShouldWriteType
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContract collectionValueContract)
{
if (HasFlag(((member != null) ? member.TypeNameHandling : null) ?? Serializer.TypeNameHandling, typeNameHandlingFlag))
return true;
if (member != null)
{
if ((member.TypeNameHandling ?? Serializer.TypeNameHandling) == TypeNameHandling.Auto
// instance and property type are different
&& contract.UnderlyingType != member.PropertyType)
{
JsonContract memberTypeContract = Serializer.ContractResolver.ResolveContract(member.PropertyType);
// instance type and the property's type's contract default type are different (no need to put the type in JSON because the type will be created by default)
if (contract.UnderlyingType != memberTypeContract.CreatedType)
return true;
}
}
else if (collectionValueContract != null)
{
if (Serializer.TypeNameHandling == TypeNameHandling.Auto && contract.UnderlyingType != collectionValueContract.UnderlyingType)
return true;
}
return false;
}
开发者ID:JungWon2,项目名称:memory_book,代码行数:25,代码来源:JsonSerializerInternalWriter.cs
示例7: ShouldWriteType
//private bool ShouldWriteTypeProperty(JsonProperty member, JsonContract contract, TypeNameHandling typeFlag)
//{
// if (HasFlag(((member != null) ? member.TypeNameHandling : null) ?? Serializer.TypeNameHandling, typeFlag))
// return true;
// if ((((member != null) ? member.TypeNameHandling : null) ?? Serializer.TypeNameHandling) == TypeNameHandling.Auto)
// || (member != null
// && (member.TypeNameHandling ?? Serializer.TypeNameHandling) == TypeNameHandling.Auto
// && contract.UnderlyingType != member.PropertyType)
// )
//}
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContract collectionValueContract)
{
if (HasFlag(((member != null) ? member.TypeNameHandling : null) ?? Serializer.TypeNameHandling, typeNameHandlingFlag))
return true;
if (member != null)
{
if ((member.TypeNameHandling ?? Serializer.TypeNameHandling) == TypeNameHandling.Auto && contract.UnderlyingType != member.PropertyType)
return true;
}
else if (collectionValueContract != null)
{
if (Serializer.TypeNameHandling == TypeNameHandling.Auto && contract.UnderlyingType != collectionValueContract.UnderlyingType)
return true;
}
return false;
}
开发者ID:xantilas,项目名称:ghalager-videobrowser-20120129,代码行数:28,代码来源:JsonSerializerInternalWriter.cs
示例8: ShouldWriteType
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
TypeNameHandling resolvedTypeNameHandling =
((member != null) ? member.TypeNameHandling : null)
?? ((containerProperty != null) ? containerProperty.ItemTypeNameHandling : null)
?? ((containerContract != null) ? containerContract.ItemTypeNameHandling : null)
?? Serializer.TypeNameHandling;
if (HasFlag(resolvedTypeNameHandling, typeNameHandlingFlag))
return true;
// instance type and the property's type's contract default type are different (no need to put the type in JSON because the type will be created by default)
if (HasFlag(resolvedTypeNameHandling, TypeNameHandling.Auto))
{
if (member != null)
{
if (contract.UnderlyingType != member.PropertyContract.CreatedType)
return true;
}
else if (containerContract != null && containerContract.ItemContract != null)
{
if (contract.UnderlyingType != containerContract.ItemContract.CreatedType)
return true;
}
}
#if !(NET35 || NET20 || WINDOWS_PHONE)
if (HasFlag(resolvedTypeNameHandling, TypeNameHandling.Auto))
{
if (contract.CreatedType == typeof(ExpandoObject))
{
//Add $type for ExpandoObject when called as root by default
return true;
}
if (member == null && containerContract != null && containerContract.UnderlyingType == typeof(object))
{
//We handling a dynamic ExpandoObject
if (containerProperty != null && contract.UnderlyingType != containerProperty.PropertyType)
{
//An IEnumerable of String (property name), Object (value) is a ExpandoObject
return true;
}
}
}
if (HasFlag(resolvedTypeNameHandling, TypeNameHandling.Objects))
{
if (member != null && member.TypeNameHandling != TypeNameHandling.None && contract.CreatedType == typeof(ExpandoObject))
{
//Add $type for ExpandoObject when called as a property by default
return true;
}
}
#endif
return false;
}
开发者ID:taliesins,项目名称:Newtonsoft.Json,代码行数:60,代码来源:JsonSerializerInternalWriter.cs
示例9: ShouldWriteType
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
TypeNameHandling resolvedTypeNameHandling =
((member != null) ? member.TypeNameHandling : null)
?? ((containerProperty != null) ? containerProperty.ItemTypeNameHandling : null)
?? ((containerContract != null) ? containerContract.ItemTypeNameHandling : null)
?? Serializer._typeNameHandling;
if (HasFlag(resolvedTypeNameHandling, typeNameHandlingFlag))
{
return true;
}
// instance type and the property's type's contract default type are different (no need to put the type in JSON because the type will be created by default)
if (HasFlag(resolvedTypeNameHandling, TypeNameHandling.Auto))
{
if (member != null)
{
if (contract.NonNullableUnderlyingType != member.PropertyContract.CreatedType)
{
return true;
}
}
else if (containerContract != null)
{
if (containerContract.ItemContract == null || contract.NonNullableUnderlyingType != containerContract.ItemContract.CreatedType)
{
return true;
}
}
else if (_rootType != null && _serializeStack.Count == _rootLevel)
{
JsonContract rootContract = Serializer._contractResolver.ResolveContract(_rootType);
if (contract.NonNullableUnderlyingType != rootContract.CreatedType)
{
return true;
}
}
}
return false;
}
开发者ID:yodiwo,项目名称:Newtonsoft.Json,代码行数:43,代码来源:JsonSerializerInternalWriter.cs
示例10: BeetleConfig
/// <summary>
/// Initializes a new instance of the <see cref="BeetleConfig" /> class.
/// </summary>
/// <param name="nullValueHandling">The null value handling.</param>
/// <param name="typeNameHandling">The type name handling.</param>
public BeetleConfig(NullValueHandling nullValueHandling, TypeNameHandling typeNameHandling)
: this(CreateSettings(nullValueHandling, typeNameHandling)) {
}
开发者ID:amartelr,项目名称:Beetle.js,代码行数:8,代码来源:BeetleConfig.cs
示例11: WriteObject
public byte[] WriteObject(object obj, Formatting formatting = Formatting.None, TypeNameHandling nameHandling = TypeNameHandling.Auto)
{
return Util.Str.GetBytes(WriteObjectAsString(obj, formatting, nameHandling));
}
开发者ID:Websilk,项目名称:Home,代码行数:4,代码来源:Serializer.cs
示例12: ReadObject
public object ReadObject(string str, Type objType, TypeNameHandling nameHandling = TypeNameHandling.Auto)
{
return JsonConvert.DeserializeObject(str, objType, new JsonSerializerSettings() { TypeNameHandling = nameHandling });
}
开发者ID:Websilk,项目名称:Home,代码行数:4,代码来源:Serializer.cs
示例13: OpenFromFile
public object OpenFromFile(Type objType, string file, TypeNameHandling nameHandling = TypeNameHandling.Auto)
{
return ReadObject(File.ReadAllText(file), objType);
}
开发者ID:Websilk,项目名称:Home,代码行数:4,代码来源:Serializer.cs
示例14: ShouldWriteType
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
TypeNameHandling? nullable1 = member != null ? member.TypeNameHandling : new TypeNameHandling?();
int num;
if (!nullable1.HasValue)
{
TypeNameHandling? nullable2 = containerProperty != null ? containerProperty.ItemTypeNameHandling : new TypeNameHandling?();
if (!nullable2.HasValue)
{
TypeNameHandling? nullable3 = containerContract != null ? containerContract.ItemTypeNameHandling : new TypeNameHandling?();
num = nullable3.HasValue ? (int) nullable3.GetValueOrDefault() : (int) this.Serializer.TypeNameHandling;
}
else
num = (int) nullable2.GetValueOrDefault();
}
else
num = (int) nullable1.GetValueOrDefault();
TypeNameHandling typeNameHandling = (TypeNameHandling) num;
if (this.HasFlag(typeNameHandling, typeNameHandlingFlag))
return true;
if (this.HasFlag(typeNameHandling, TypeNameHandling.Auto))
{
if (member != null)
{
if (contract.UnderlyingType != member.PropertyContract.CreatedType)
return true;
}
else if (containerContract != null && containerContract.ItemContract != null && contract.UnderlyingType != containerContract.ItemContract.CreatedType)
return true;
}
return false;
}
开发者ID:Zeludon,项目名称:FEZ,代码行数:32,代码来源:JsonSerializerInternalWriter.cs
示例15: ShouldWriteType
// Token: 0x06000C09 RID: 3081
// RVA: 0x000478E4 File Offset: 0x00045AE4
private bool ShouldWriteType(TypeNameHandling typeNameHandlingFlag, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
TypeNameHandling value = ((member != null) ? member.TypeNameHandling : null) ?? (((containerProperty != null) ? containerProperty.ItemTypeNameHandling : null) ?? (((containerContract != null) ? containerContract.ItemTypeNameHandling : null) ?? this.Serializer._typeNameHandling));
if (this.HasFlag(value, typeNameHandlingFlag))
{
return true;
}
if (this.HasFlag(value, TypeNameHandling.Auto))
{
if (member != null)
{
if (contract.UnderlyingType != member.PropertyContract.CreatedType)
{
return true;
}
}
else if (containerContract != null)
{
if (containerContract.ItemContract == null || contract.UnderlyingType != containerContract.ItemContract.CreatedType)
{
return true;
}
}
else if (this._rootContract != null && this._serializeStack.Count == this._rootLevel && contract.UnderlyingType != this._rootContract.CreatedType)
{
return true;
}
}
return false;
}
开发者ID:newchild,项目名称:Project-DayZero,代码行数:32,代码来源:JsonSerializerInternalWriter.cs
示例16: HasFlag
private bool HasFlag(TypeNameHandling value, TypeNameHandling flag)
{
return ((value & flag) == flag);
}
开发者ID:draptik,项目名称:RepoSync,代码行数:4,代码来源:JsonSerializerInternalWriter.cs
注:本文中的TypeNameHandling类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论