Skip to content

Instantly share code, notes, and snippets.

View beachside-project's full-sized avatar
😄

Atsushi YOKOHAMA beachside-project

😄
View GitHub Profile
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string[] Hobbies{ get; set; }
public List<Phone> Phones { get; set; }
public string FullName => $"{FirstName} {LastName}";
@beachside-project
beachside-project / jsonDemo_main2_camel.cs
Created April 15, 2016 09:41
jsonDemo main2 JsonSerializerSettings - CamelCase
//Jsonにインデントつけるには... +JsonSerializerSettingsでキャメルケース出力
var shinobuJsonWithIndention = JsonConvert.SerializeObject(shinobu, Formatting.Indented, new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
Console.WriteLine(shinobuJsonWithIndention);
@beachside-project
beachside-project / jsonDemo_JsonSerializable.cs
Created April 15, 2016 11:11
jsonDemo JsonSerializableModel
public abstract class JsonSerializable
{
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
public string ToJsonString() => JsonConvert.SerializeObject(this, Settings);
public string ToJsonString(JsonSerializerSettings settings) => JsonConvert.SerializeObject(this, settings);
@beachside-project
beachside-project / jsonDemo_main1.cs
Last active April 15, 2016 11:46
jsonDemo_main1
class Program
{
static void Main(string[] args)
{
var shinobu = new Person()
{
FirstName = "shinobu",
LastName = "oshino",
Age = 598,
@beachside-project
beachside-project / jsonDemo_person2_attribute.cs
Created April 15, 2016 11:52
jsonDemo_person2_attribute
public class Person
{
[JsonProperty(PropertyName = "firstName")]
public string FirstName { get; set; }
[JsonProperty(PropertyName = "lastName")]
public string LastName { get; set; }
[JsonProperty(PropertyName = "age")]
public int Age { get; set; }
@beachside-project
beachside-project / jsonDemo_SnakeCaseContractResolver.cs
Last active April 18, 2016 01:55
jsonDemo_SnakeCaseContractResolver
public class SnakeCaseContractResolver : DefaultContractResolver
{
private const string SnakeDelimiter = "_";
protected override IList<JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization)
=> base.CreateProperties(type, memberSerialization).Select(ConvertSnakeCasePropertyName).ToList();
private static JsonProperty ConvertSnakeCasePropertyName(JsonProperty p)
{
var target = p.PropertyName;
var shinobu = new Person()
{
FirstName = "shinobu",
LastName = "oshino",
Age = 598,
Favorites = new[] { "golden chocolate", "pon de ring" },
Phones = new List<Phone>()
{
new Phone() {PhoneNumber = "000-000-111",ModelName = "Lumia"},
public static class EnumerableExtension
{
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source);
}
public static class EnumerableExtension
{
public static bool ContainsDuplicate(this IEnumerable<string> source) => source.GroupBy(i => i).SelectMany(g => g.Skip(1)).Any();
}
using System;
using System.Collections.Generic;
using Microsoft.Bot.Builder.FormFlow;
namespace FormFlow1.Dialogs
{
[Serializable]
public class SandwichOrder
{
public SandwichOptions? Sandwich;