// 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.Reflection; using System.Resources; using Microsoft.Framework.Internal; using Microsoft.Framework.Localization.Internal; using Microsoft.Framework.Runtime; namespace Microsoft.Framework.Localization { /// /// An that creates instances of . /// public class ResourceManagerStringLocalizerFactory : IStringLocalizerFactory { private readonly IApplicationEnvironment _applicationEnvironment; /// /// Creates a new . /// /// public ResourceManagerStringLocalizerFactory([NotNull] IApplicationEnvironment applicationEnvironment) { _applicationEnvironment = applicationEnvironment; } /// /// Creates a using the and /// of the specified . /// /// The . /// The . public IStringLocalizer Create([NotNull] Type resourceSource) { var typeInfo = resourceSource.GetTypeInfo(); var assembly = new AssemblyWrapper(typeInfo.Assembly); var baseName = typeInfo.FullName; return new ResourceManagerStringLocalizer(new ResourceManager(resourceSource), assembly, baseName); } /// /// Creates a . /// /// The base name of the resource to load strings from. /// The location to load resources from. /// The . public IStringLocalizer Create([NotNull] string baseName, [NotNull] string location) { var assembly = Assembly.Load(new AssemblyName(location ?? _applicationEnvironment.ApplicationName)); return new ResourceManagerStringLocalizer( new ResourceManager(baseName, assembly), new AssemblyWrapper(assembly), baseName); } } }