parent
919734cbb2
commit
a61d9b6921
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
|
|
@ -56,6 +56,10 @@ namespace Microsoft.Extensions.Localization
|
|||
SearchedLocation = searchedLocation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts the <see cref="LocalizedString"/> to a <see cref="string"/>.
|
||||
/// </summary>
|
||||
/// <param name="localizedString">The string to be implicitly converted.</param>
|
||||
public static implicit operator string(LocalizedString localizedString)
|
||||
{
|
||||
return localizedString?.Value;
|
||||
|
|
@ -87,4 +91,4 @@ namespace Microsoft.Extensions.Localization
|
|||
/// <returns>The actual string.</returns>
|
||||
public override string ToString() => Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.Extensions.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for operating on <see cref="IStringLocalizer" />'s.
|
||||
/// </summary>
|
||||
public static class StringLocalizerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,12 @@ namespace Microsoft.Extensions.Localization
|
|||
/// </summary>
|
||||
public class LocalizationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LocalizationOptions" />.
|
||||
/// </summary>
|
||||
public LocalizationOptions()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// The relative path under application root where resource files are located.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
|
@ -14,6 +14,13 @@ namespace Microsoft.Extensions.Localization
|
|||
{
|
||||
private readonly ConcurrentDictionary<string, IList<string>> _cache = new ConcurrentDictionary<string, IList<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ResourceNamesCache" />
|
||||
/// </summary>
|
||||
public ResourceNamesCache()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IList<string> GetOrAdd(string name, Func<string, IList<string>> valueFactory)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ using System.Threading;
|
|||
|
||||
namespace Microsoft.Extensions.ObjectPool
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of <see cref="ObjectPool<T>"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to pool objects for.</typeparam>
|
||||
public class DefaultObjectPool<T> : ObjectPool<T> where T : class
|
||||
{
|
||||
private protected readonly ObjectWrapper[] _items;
|
||||
|
|
@ -18,11 +22,20 @@ namespace Microsoft.Extensions.ObjectPool
|
|||
// This class was introduced in 2.1 to avoid the interface call where possible
|
||||
private protected readonly PooledObjectPolicy<T> _fastPolicy;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="DefaultObjectPool<T>"/>.
|
||||
/// </summary>
|
||||
/// <param name="policy">The pooling policy to use.</param>
|
||||
public DefaultObjectPool(IPooledObjectPolicy<T> policy)
|
||||
: this(policy, Environment.ProcessorCount * 2)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="DefaultObjectPool<T>"/>.
|
||||
/// </summary>
|
||||
/// <param name="policy">The pooling policy to use.</param>
|
||||
/// <param name="maximumRetained">The maximum number of objects to retain in the pool.</param>
|
||||
public DefaultObjectPool(IPooledObjectPolicy<T> policy, int maximumRetained)
|
||||
{
|
||||
_policy = policy ?? throw new ArgumentNullException(nameof(policy));
|
||||
|
|
|
|||
|
|
@ -5,10 +5,17 @@ using System;
|
|||
|
||||
namespace Microsoft.Extensions.ObjectPool
|
||||
{
|
||||
/// <summary>
|
||||
/// A provider of <see cref="DefaultObjectPool<T>"/>'s.
|
||||
/// </summary>
|
||||
public class DefaultObjectPoolProvider : ObjectPoolProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum number of objects to retain in the pool.
|
||||
/// </summary>
|
||||
public int MaximumRetained { get; set; } = Environment.ProcessorCount * 2;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ObjectPool<T> Create<T>(IPooledObjectPolicy<T> policy)
|
||||
{
|
||||
if (policy == null)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,23 @@
|
|||
|
||||
namespace Microsoft.Extensions.ObjectPool
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a policy for managing pooled objects.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object which is being pooled.</typeparam>
|
||||
public interface IPooledObjectPolicy<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <returns>The <typeparamref name="T"/> which was created.</returns>
|
||||
T Create();
|
||||
|
||||
/// <summary>
|
||||
/// Put an object in the pool.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to put in the pool.</param>
|
||||
/// <returns><code>true</code> if put in the pool.</returns>
|
||||
bool Return(T obj);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,31 @@
|
|||
|
||||
namespace Microsoft.Extensions.ObjectPool
|
||||
{
|
||||
/// <summary>
|
||||
/// A pool of objects.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of objects to pool.</typeparam>
|
||||
public abstract class ObjectPool<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns an object from the pool.
|
||||
/// </summary>
|
||||
/// <returns>An object from the pool.</returns>
|
||||
public abstract T Get();
|
||||
|
||||
/// <summary>
|
||||
/// Put an object in the pool.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to add to the pool.</param>
|
||||
public abstract void Return(T obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Methods for creating <see cref="ObjectPool<T>"/>'s.
|
||||
/// </summary>
|
||||
public static class ObjectPool
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static ObjectPool<T> Create<T>(IPooledObjectPolicy<T> policy = null) where T : class, new()
|
||||
{
|
||||
var provider = new DefaultObjectPoolProvider();
|
||||
|
|
|
|||
|
|
@ -3,13 +3,24 @@
|
|||
|
||||
namespace Microsoft.Extensions.ObjectPool
|
||||
{
|
||||
/// <summary>
|
||||
/// A provider of <see cref="ObjectPool<T>"/>'s.
|
||||
/// </summary>
|
||||
public abstract class ObjectPoolProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ObjectPool"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to create a pool for.</typeparam>
|
||||
public ObjectPool<T> Create<T>() where T : class, new()
|
||||
{
|
||||
return Create<T>(new DefaultPooledObjectPolicy<T>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ObjectPool"/> with the given <see cref="IPooledObjectPolicy<T>"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to create a pool for.</typeparam>
|
||||
public abstract ObjectPool<T> Create<T>(IPooledObjectPolicy<T> policy) where T : class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue