public IResourceManager GetResourceManager(Type objectType, bool includeHierarchy) { ArgumentUtility.CheckNotNull("objectType", objectType); ArgumentUtility.CheckNotNull("includeHierarchy", includeHierarchy); var targetType = MixinTypeUtility.GetUnderlyingTargetType(objectType); var result = s_resolver.Value.Resolve(targetType); var mixinResourceManager = s_mixinGlobalizationService.Value.GetResourceManager(TypeAdapter.Create(targetType)); if (includeHierarchy) { if (result.IsNull && mixinResourceManager.IsNull) { throw new ResourceException(string.Format("Type {0} and its base classes do not define a resource attribute.", objectType.FullName)); } return(ResourceManagerSet.Create(result.DefinedResourceManager, mixinResourceManager, result.InheritedResourceManager)); } if (result.IsNull && mixinResourceManager.IsNull) { throw new ResourceException(string.Format("Type {0} and its base classes do not define a resource attribute.", objectType.FullName)); } if (result.DefinedResourceManager.IsNull && !mixinResourceManager.IsNull) { return(mixinResourceManager); } if (result.DefinedResourceManager.IsNull) // we already know there is a resource defined on a base-type so no additional checks are required. { return(MultiLingualResources.GetResourceManager(targetType.BaseType, false)); } return(ResourceManagerSet.Create(result.DefinedResourceManager, mixinResourceManager)); }
public void AttributesOnBaseAndClass_InheritedTrue() { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(InheritedClassWithMultiLingualResourcesAttributes), true); Assert.That(resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.OnInherited, NamedResources.OnTarget })); }
public void AttributesOnClass() { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(ClassWithMultiLingualResourcesAttributes), false); Assert.That(resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.OnTarget })); }
public void AttributesOnBase_DoesNotThrowResourceExceptionBecauseOfBug() { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(InheritedClassWithoutMultiLingualResourcesAttributes), false); Assert.That(resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.OnInherited })); }
/// <summary> Find the <see cref="IResourceManager"/> for this renderer. </summary> /// <param name="localResourcesType"> /// A type with the <see cref="MultiLingualResourcesAttribute"/> applied to it. Typically an <b>enum</b> or the derived class itself. /// </param> /// <param name="controlResourceManager"> The <see cref="IResourceManager"/> of the control for which the rendering is done. </param> /// <returns>An <see cref="IResourceManager"/> from which all resources for this renderer can be obtained.</returns> protected IResourceManager GetResourceManager(Type localResourcesType, IResourceManager controlResourceManager) { ArgumentUtility.CheckNotNull("localResourcesType", localResourcesType); ArgumentUtility.CheckNotNull("controlResourceManager", controlResourceManager); return(_resourceManagerCache.GetOrCreateValue( Tuple.Create(localResourcesType, controlResourceManager), key => ResourceManagerSet.Create(key.Item2, _globalizationService.GetResourceManager(key.Item1)))); }
public void AttributesFromMixin_InheritedTrue() { using (MixinConfiguration.BuildNew() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(ClassWithoutMultiLingualResourcesAttributes), true); Assert.That(resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.OnMixin1 })); } }
/// <summary> Find the <see cref="IResourceManager"/> for this control. </summary> /// <param name="localResourcesType"> /// A type with the <see cref="MultiLingualResourcesAttribute"/> applied to it. Typically an <b>enum</b> or the derived class itself. /// </param> /// <returns>An <see cref="IResourceManager"/> from which all resources for this control can be obtained.</returns> protected IResourceManager GetResourceManager(Type localResourcesType) { ArgumentUtility.CheckNotNull("localResourcesType", localResourcesType); return(_resourceManagerCache.GetOrCreateValue( Tuple.Create(localResourcesType, NamingContainer), key => { var localResourceManager = GlobalizationService.GetResourceManager(localResourcesType); var namingContainerResourceManager = ResourceManagerUtility.GetResourceManager(NamingContainer, true); return ResourceManagerSet.Create(namingContainerResourceManager, localResourceManager); })); }
public void AttributesFromMultipleMixins_InheritedFalse() { using (MixinConfiguration.BuildNew() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinAddingMultiLingualResourcesAttributes2>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(ClassWithoutMultiLingualResourcesAttributes), false); Assert.That(resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin1, NamedResources.OnMixin2a, NamedResources.OnMixin2b })); Assert.That(resourceManager.ResourceManagers.Take(1).Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.OnMixin1 })); Assert.That(resourceManager.ResourceManagers.Skip(1).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin2a, NamedResources.OnMixin2b })); } }
private static IResourceManager CombineResourceManagers(IResourceManager definedResourceManager, IResourceManager inheritedResourceManager) { if (definedResourceManager.IsNull && inheritedResourceManager.IsNull) { return(NullResourceManager.Instance); } if (definedResourceManager.IsNull) { return(inheritedResourceManager); } if (inheritedResourceManager.IsNull) { return(definedResourceManager); } return(ResourceManagerSet.Create(definedResourceManager, inheritedResourceManager)); }
/// <summary> /// Find the <see cref="IResourceManager"/> for this <see cref="ValidationStateViewer"/>. /// </summary> /// <returns></returns> protected IResourceManager GetResourceManager() { // Provider has already been identified. if (_cachedResourceManager != null) { return(_cachedResourceManager); } // Get the resource managers IResourceManager localResourceManager = GlobalizationService.GetResourceManager(typeof(ResourceIdentifier)); IResourceManager namingContainerResourceManager = ResourceManagerUtility.GetResourceManager(NamingContainer, true); _cachedResourceManager = ResourceManagerSet.Create(namingContainerResourceManager, localResourceManager); return(_cachedResourceManager); }
/// <summary> Find the <see cref="IResourceManager"/> for this control info. </summary> /// <param name="localResourcesType"> /// A type with the <see cref="MultiLingualResourcesAttribute"/> applied to it. /// Typically an <b>enum</b> or the derived class itself. /// </param> protected IResourceManager GetResourceManager(Type localResourcesType) { ArgumentUtility.CheckNotNull("localResourcesType", localResourcesType); // Provider has already been identified. if (_cachedResourceManager != null) { return(_cachedResourceManager); } // Get the resource managers var localResourceManager = GlobalizationService.GetResourceManager(localResourcesType); var pageResourceManager = ResourceManagerUtility.GetResourceManager(_page.WrappedInstance, true); _cachedResourceManager = ResourceManagerSet.Create(pageResourceManager, localResourceManager); return(_cachedResourceManager); }
public void AttributesFromMixinsAndBaseAndClass_InheritedTrue() { using (MixinConfiguration.BuildNew() .ForClass <InheritedClassWithMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinAddingMultiLingualResourcesAttributes2>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(InheritedClassWithMultiLingualResourcesAttributes), true); Assert.That( resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnInherited, NamedResources.OnMixin1, NamedResources.OnMixin2a, NamedResources.OnMixin2b, NamedResources.OnTarget })); Assert.That(resourceManager.ResourceManagers.Take(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnInherited, NamedResources.OnMixin1 })); Assert.That(resourceManager.ResourceManagers.Skip(2).Take(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin2a, NamedResources.OnMixin2b })); Assert.That(resourceManager.ResourceManagers.Skip(4).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnTarget })); } }
/// <summary> Find the <see cref="IResourceManager"/> for this control. </summary> /// <param name="localResourcesType"> /// A type with the <see cref="MultiLingualResourcesAttribute"/> applied to it. /// Typically an <b>enum</b> or the derived class itself. /// </param> protected IResourceManager GetResourceManager(Type localResourcesType) { //Remotion.Utilities.ArgumentUtility.CheckNotNull ("localResourcesType", localResourcesType); // Provider has already been identified. if (_cachedResourceManager != null) { return(_cachedResourceManager); } // Get the resource managers var localResourceManager = GlobalizationService.GetResourceManager(localResourcesType); var namingContainerResourceManager = ResourceManagerUtility.GetResourceManager(NamingContainer, true); _cachedResourceManager = ResourceManagerSet.Create(namingContainerResourceManager, localResourceManager); return(_cachedResourceManager); }
public void AttributesFromMixinOfMixin_InheritedFalse() { using (MixinConfiguration.BuildNew() .ForClass <ClassWithoutMultiLingualResourcesAttributes>() .AddMixin <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinAddingMultiLingualResourcesAttributes2>() .ForClass <MixinAddingMultiLingualResourcesAttributes1>() .AddMixin <MixinOfMixinWithResources>() .EnterScope()) { ResourceManagerSet resourceManager = (ResourceManagerSet)MixedMultiLingualResources.GetResourceManager(typeof(ClassWithoutMultiLingualResourcesAttributes), false); //Note: MixinOfMixin was previously sorted after the introducing mixin, but there is no know client code that actually used MixinOfMixin with resources. Assert.That( resourceManager.ResourceManagers.Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.MixinOfMixinWithResources, NamedResources.OnMixin1, NamedResources.OnMixin2a, NamedResources.OnMixin2b })); Assert.That(resourceManager.ResourceManagers.Take(2).Select(rm => rm.Name), Is.EqualTo(new[] { NamedResources.MixinOfMixinWithResources, NamedResources.OnMixin1 })); Assert.That(resourceManager.ResourceManagers.Skip(2).Select(rm => rm.Name), Is.EquivalentTo(new[] { NamedResources.OnMixin2a, NamedResources.OnMixin2b })); } }
protected IResourceManager GetResourceManager(Type resourceEnumType) { ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("resourceEnumType", resourceEnumType, typeof(Enum)); return(ResourceManagerSet.Create(GlobalizationService.GetResourceManager(TypeAdapter.Create(resourceEnumType)), GetResourceManager())); }
protected virtual IResourceManager GetResourceManager(BocListRenderingContext renderingContext) { return(ResourceManagerSet.Create( renderingContext.Control.GetResourceManager(), _globalizationService.GetResourceManager(typeof(ResourceIdentifier)))); }