本文整理汇总了C#中Formatting类的典型用法代码示例。如果您正苦于以下问题:C# Formatting类的具体用法?C# Formatting怎么用?C# Formatting使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Formatting类属于命名空间,在下文中一共展示了Formatting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToJson
public string ToJson(Formatting format = Formatting.None)
{
JsonSerializerSettings setting = new JsonSerializerSettings();
setting.NullValueHandling = NullValueHandling.Ignore;
string json = JsonConvert.SerializeObject(this, format, setting);
return json;
}
示例2: GetTagName
private static string GetTagName(Formatting formatting)
{
switch (formatting)
{
case Formatting.Bold:
return "b";
case Formatting.Italic:
return "i";
case Formatting.Underline:
return "u";
case Formatting.Strikethrough:
return "del";
case Formatting.Subscript:
return "sub";
case Formatting.Superscript:
return "sup";
default:
throw new ArgumentOutOfRangeException("formatting");
}
}
示例3: ForTypesWithoutInterfacesCustomSerializerSerializesTheSameAsDefaultSerializer
public void ForTypesWithoutInterfacesCustomSerializerSerializesTheSameAsDefaultSerializer(
object instance,
string defaultNamespace,
Type[] extraTypes,
string rootElementName,
Encoding encoding,
Formatting formatting,
XmlSerializerNamespaces namespaces)
{
var defaultSerializer =
(IXmlSerializer)Activator.CreateInstance(
typeof(DefaultSerializer<>).MakeGenericType(instance.GetType()),
defaultNamespace,
extraTypes,
rootElementName);
var customSerializer =
(IXmlSerializer)Activator.CreateInstance(
typeof(CustomSerializer<>).MakeGenericType(instance.GetType()),
defaultNamespace,
extraTypes,
rootElementName);
var defaultXml = defaultSerializer.SerializeObject(instance, namespaces, encoding, formatting);
var customXml = customSerializer.SerializeObject(instance, namespaces, encoding, formatting);
Console.WriteLine("Default XML:");
Console.WriteLine(defaultXml);
Console.WriteLine();
Console.WriteLine("Custom XML:");
Console.WriteLine(customXml);
Assert.That(customXml, Is.EqualTo(defaultXml));
}
示例4: DocumentWriter
public DocumentWriter(Formatting formatting)
: this(formatting,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
})
{
}
示例5: JsonNetResult
public JsonNetResult(object data,
Formatting formatting = Formatting.None,
JsonSerializerSettings settings = null)
{
Data = data;
SerializerSettings = settings ?? new JsonSerializerSettings();
Formatting = formatting;
}
示例6: WithJsonSerializer
/// <summary>
/// To provide custom serialization using the <see cref="Newtonsoft.Json.JsonSerializer" />.
/// </summary>
/// <param name="configuration">The bus configuration to apply the serializer to.</param>
/// <param name="settings">To configure serialization settings.</param>
/// <param name="formatting">To configure serialization formatting.</param>
/// <param name="fallbackSerializer">To add a fallback serializer (if i.e you want to support both XML and Json)</param>
/// <returns>Bus configuration.</returns>
public static BusBuilderConfiguration.Config WithJsonSerializer(
this BusBuilderConfiguration.Config configuration,
JsonSerializerSettings settings,
Formatting formatting = Formatting.None,
ISerializer fallbackSerializer = null)
{
return configuration.WithSerializer(new JsonSerializer(settings, formatting, fallbackSerializer));
}
开发者ID:AtmosphereMessaging,项目名称:Cumulus-vNext,代码行数:16,代码来源:BusBuilderConfigurationJsonSerializerExtensions.cs
示例7: 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
});
}
示例8: 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));
}
示例9: InternalToString
internal override string InternalToString(Formatting format, int depth)
{
if (Value != null && Value.Length > 0)
return string.Concat("\"base64:",
Convert.ToBase64String(this.Value),
"\"");
else
return "\"base64:\"";
}
示例10: JsonNetResult
public JsonNetResult(object data)
{
this.data = data;
formatting = Formatting.None;
serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
}
示例11: Serialize
public static string Serialize(LanguageDefinition definition, Formatting formatting, bool serializeAsArrays = false)
{
//var json = JsonConvert.SerializeObject(definition, formatting, new InlineDefinitionJsonConverter(), new StringDefinitionJsonConverter(serializeAsArrays));
var settings = new JsonSerializerSettings();// {TypeNameHandling = TypeNameHandling.All};
settings.Converters.Add(new InlineDefinitionJsonConverter(serializeAsArrays));
settings.Converters.Add(new StringDefinitionJsonConverter(serializeAsArrays));
var json = JsonConvert.SerializeObject(definition, formatting, settings);
return json;
}
示例12: SinglePage
public static string SinglePage(Formatting.FormattedHtml htmlContent)
{
var m = new Models.SingleFileModel()
{
Stylesheets = new[] { htmlContent.Stylesheet },
PreformattedHtml = htmlContent.Html,
Javascript = new[] { htmlContent.Javascript }
};
return RenderSingleFile(m);
}
示例13: JsonNetResult
public JsonNetResult()
{
SerializerSettings = new JsonSerializerSettings();
//SerializerSettings.Converters.Add(new JavaScriptDateTimeConverter());
SerializerSettings.Converters.Add(new IsoDateTimeConverter());
SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
Formatting = Formatting.None;
}
示例14: ObjectToJson
public static string ObjectToJson(this IHtmlHelper helper, object input, Formatting jsonFormatting, params JsonConverter[] converters)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
if (converters != null) {
foreach (JsonConverter converter in converters) {
settings.Converters.Add(converter);
}
}
return JsonConvert.SerializeObject(input, jsonFormatting, settings);
}
示例15: DocumentWriter
public DocumentWriter(Formatting formatting)
: this(
formatting,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFF'Z'",
})
{
}