示例#1
0
        /// <summary>
        /// Adds a string resource the the resources.
        /// </summary>
        public bool TryAddString(ResourceDataEntry entry)
        {
            if (m_stringValues.ContainsKey(entry.Name))
            {
                return(false);
            }

            m_stringValues.Add(entry.Name, entry);
            return(true);
        }
示例#2
0
        private static ResourceDataEntry ParseDataElement(XElement dataElement, string filePath)
        {
            var entry = new ResourceDataEntry();

            foreach (var attribute in dataElement.Attributes())
            {
                if (attribute.Name == ResWNames.Space)
                {
                    // xmlns space declaration is okay.
                    continue;
                }

                if (attribute.Name == ResWNames.Name)
                {
                    entry.Name = attribute.Value;
                    continue;
                }

                throw new ResGenLiteException(
                          $"{GetErrorPrefix(filePath, attribute)}Unexpected attribute encountered. Only '{ResWNames.Name}' is allowed on '{ResWNames.Data}' element. Encountered '{attribute.Name}'");
            }

            if (string.IsNullOrEmpty(entry.Name))
            {
                throw new ResGenLiteException(
                          $"{GetErrorPrefix(filePath, dataElement)}Required attribute '{ResWNames.Name}' on element '{ResWNames.Data}' is missing.");
            }

            foreach (var dataChild in dataElement.Elements())
            {
                if (dataChild.Name == ResWNames.Comment)
                {
                    entry.Comment = dataChild.Value;
                    continue;
                }

                if (dataChild.Name == ResWNames.Value)
                {
                    entry.Value = dataChild.Value;
                    continue;
                }

                throw new ResGenLiteException(
                          $"{GetErrorPrefix(filePath, dataChild)}Unexpected element encountered. Only '{ResWNames.Value}' is allowed to be a child of '{ResWNames.Data}' element. Encountered '{dataChild.Name}'");
            }
            if (entry.Value == null)
            {
                throw new ResGenLiteException(
                          $"{GetErrorPrefix(filePath, dataElement)}Required element '{ResWNames.Value}' under '{ResWNames.Data}' is missing.");
            }

            return(entry);
        }