Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / ResourceAttribute.cs
blob1df91764da8a0bbac79e0fb54706b8dbf4418866
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework
17 using System;
19 using Castle.MonoRail.Framework.Internal;
21 /// <summary>
22 /// Declares that for the specified class or method, the given resource file should be
23 /// loaded and set available in the PropertyBag with the specified name.
24 /// </summary>
25 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple=true, Inherited=true), Serializable]
26 public class ResourceAttribute : Attribute, IResourceDescriptorBuilder
28 private String name, resourceName, cultureName, assemblyName;
29 private Type resourceType;
31 /// <summary>
32 /// Constructs a resource attribute, with the specified name, based
33 /// on the resource in a satellite assembly.
34 /// </summary>
35 /// <param name="name">Name the resource will be available as in the PropertyBag</param>
36 /// <param name="resourceName">Fully qualified name of the resource in the sattelite assembly</param>
37 public ResourceAttribute( String name, String resourceName )
39 this.name = name;
40 this.resourceName = resourceName;
42 if (resourceName.IndexOf(',') > 0)
44 String[] pair = resourceName.Split(',');
45 this.resourceName = pair[0].Trim();
46 this.assemblyName = pair[1].Trim();
50 /// <summary>
51 /// Gets or sets the Name the of resource that will be available in the PropertyBag.
52 /// </summary>
53 /// <value>The name.</value>
54 public String Name
56 get { return name; }
57 set { name = value; }
60 /// <summary>
61 /// Gets or sets the Fully qualified name of the resource in the sattelite assembly.
62 /// </summary>
63 /// <value>The name of the resource.</value>
64 public String ResourceName
66 get { return resourceName; }
67 set { resourceName = value; }
70 /// <summary>
71 /// Gets or sets the name of the culture.
72 /// </summary>
73 /// <value>The name of the culture.</value>
74 public String CultureName
76 get { return cultureName; }
77 set { cultureName = value; }
80 /// <summary>
81 /// Gets or sets the name of the assembly.
82 /// </summary>
83 /// <value>The name of the assembly.</value>
84 public String AssemblyName
86 get { return assemblyName; }
87 set { assemblyName = value; }
90 /// <summary>
91 /// Gets or sets the type of the resource.
92 /// </summary>
93 /// <value>The type of the resource.</value>
94 public Type ResourceType
96 get { return resourceType; }
97 set { resourceType = value; }
100 /// <summary>
101 /// <see cref="IResourceDescriptorBuilder"/> implementation.
102 /// Builds the resource descriptors.
103 /// </summary>
104 /// <returns></returns>
105 public ResourceDescriptor[] BuildResourceDescriptors()
107 return new ResourceDescriptor[] { new ResourceDescriptor(resourceType,
108 name,
109 resourceName,
110 cultureName,
111 assemblyName) };