Пример #1
0
        /// <summary>
        /// Gets a string from the resource file and formats it using the specified arguments.
        /// </summary>
        /// <param name="name">The resource identifier of the string to retrieve.</param>
        /// <param name="args">An array of objects to use in the formatting. Can be null or empty.</param>
        /// <returns>A formatted string from the resource file.</returns>
        public string GetString(string name, params object[] args)
        {
            string returnString = this.missingManifestString;

            // If we previously tried to get a string from the resource file and we had a
            // MissingManifestResourceException, then we don't want to try again. Exceptions
            // are expensive especially when we could be getting lots of strings.
            if (!this.isMissingManifest)
            {
                try
                {
                    // First give the subclass a chance to retrieve the string
                    if (this.IsStringDefined(name))
                    {
                        returnString = this.manager.GetString(name, CultureInfo.CurrentUICulture);
                    }
                    //\ Try getting the string from our assembly if the subclass can't handle it
                    else if (SconceStrings.IsValidStringName(name))
                    {
                        returnString = thisAssemblyManager.GetString(name, CultureInfo.CurrentUICulture);
                    }
                    else
                    {
                        Tracer.WriteLineWarning(classType, "GetString", "The string id '{0}' is not defined.", name);
                        returnString = name;
                    }

                    // Format the message if there are arguments specified. Note that we format
                    // using the CurrentCulture and not the CurrentUICulture (although in almost all
                    // cases it will be the same).
                    if (returnString != null && args != null && args.Length > 0)
                    {
                        returnString = String.Format(CultureInfo.CurrentCulture, returnString, args);
                    }
                }
                catch (MissingManifestResourceException e)
                {
                    this.isMissingManifest = true;
                    Tracer.Fail("The resource cannot be found in the assembly: {0}", e);
                }
            }

            return(returnString);
        }
Пример #2
0
        //==========================================================================================
        // Properties
        //==========================================================================================

        #endregion

        #region Methods
        //==========================================================================================
        // Methods
        //==========================================================================================

        /// <summary>
        /// Returns a value indicating whether the specified name is a defined string resource name.
        /// </summary>
        /// <param name="name">The resource identifier to check.</param>
        /// <returns>true if the string identifier is defined in our assembly; otherwise, false.</returns>
        public virtual bool IsStringDefined(string name)
        {
            return(SconceStrings.IsValidStringName(name));
        }