Files
cefsharp/CefSharp/ModelBinding/DefaultFieldNameConverter.cs
T
Chris bef5dd37c4 Maintenance - Fixed formatting, file encoding, and copyright year (#2504)
* Applied formatting

* Fixed file encoding + Updated copyright year

* Updated License

* Fixed more file encoding

* Copyright notice now shows the year the file was created
2018-09-10 10:41:13 +10:00

49 lines
1.4 KiB
C#

// 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
{
/// <summary>
/// Default field name converter
/// Converts camel case to pascal case
/// </summary>
public class DefaultFieldNameConverter : IFieldNameConverter
{
private readonly ConcurrentDictionary<string, string> cache;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultFieldNameConverter"/> class.
/// </summary>
public DefaultFieldNameConverter()
{
this.cache = new ConcurrentDictionary<string, string>();
}
/// <summary>
/// Converts a field name to a property name
/// </summary>
/// <param name="fieldName">Field name</param>
/// <returns>Property name</returns>
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();
});
}
}
}