// Copyright © 2016 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System.Collections.Concurrent; namespace CefSharp.ModelBinding { /// /// Default field name converter /// Converts camel case to pascal case /// public class DefaultFieldNameConverter : IFieldNameConverter { private readonly ConcurrentDictionary cache; /// /// Initializes a new instance of the class. /// public DefaultFieldNameConverter() { this.cache = new ConcurrentDictionary(); } /// /// Converts a field name to a property name /// /// Field name /// Property name public string Convert(string fieldName) { if (string.IsNullOrWhiteSpace(fieldName)) { return fieldName; } return this.cache.GetOrAdd(fieldName, name => { if (name.Length > 1) { return char.ToUpperInvariant(name[0]) + name.Substring(1); } return name.ToUpperInvariant(); }); } } }