コード例 #1
0
        public List <Resource> ExtractResources(XmlElement element)
        {
            List <Resource>   result   = new List <Resource>();
            List <XmlElement> toRemove = new List <XmlElement>();

            foreach (XmlElement child in element.Children)
            {
                if (ParsingHelper.IsResourceTag(child))
                {
                    // parse content to get resources
                    foreach (XmlElement resourceElement in child.Children)
                    {
                        XmlAttribute keyAttribute = ParsingHelper.GetResourceKeyAttribute(resourceElement);
                        if (keyAttribute == null)
                        {
                            BindingPreprocess.Logger.LogError("You have a resource of type {0} with no key", string.IsNullOrWhiteSpace(resourceElement.NamespaceName) ? resourceElement.LocalName : string.Format("{0}:{1}", resourceElement.NamespaceName, resourceElement.LocalName));
                        }
                        else
                        {
                            Resource resource = new Resource(keyAttribute.Value)
                            {
                                ResourceElement = resourceElement,
                                Type            = resourceElement.LocalName,
                            };
                            foreach (XmlAttribute attribute in resourceElement.Attributes.Where(x => !ParsingHelper.IsResourceKeyAttribute(x)))
                            {
                                resource.Properties.Add(attribute.LocalName, attribute.Value);
                            }
                            result.Add(resource);
                        }
                    }

                    // and then mark it for remove from the tree since it does not need to be there anymore
                    toRemove.Add(child);
                }
                else
                {
                    result.AddRange(ExtractResources(child));
                }
            }

            foreach (XmlElement toRemoveChild in toRemove)
            {
                element.Children.Remove(toRemoveChild);
            }

            return(result);
        }
コード例 #2
0
        public List <Resource> ExtractGlobalResources(XmlElement element)
        {
            List <Resource> result = new List <Resource>();

            if (ParsingHelper.IsResourceTag(element))
            {
                // parse content to get resources
                foreach (XmlElement resourceElement in element.Children)
                {
                    XmlAttribute keyAttribute = ParsingHelper.GetResourceKeyAttribute(resourceElement);
                    if (keyAttribute == null)
                    {
                        BindingPreprocess.Logger.LogError("You have a resource of type {0} with no key", string.IsNullOrWhiteSpace(resourceElement.NamespaceName) ? resourceElement.LocalName : string.Format("{0}:{1}", resourceElement.NamespaceName, resourceElement.LocalName));
                    }
                    else
                    {
                        Resource resource = new Resource(keyAttribute.Value)
                        {
                            ResourceElement = resourceElement,
                            Type            = resourceElement.LocalName,
                        };
                        foreach (XmlAttribute attribute in resourceElement.Attributes.Where(x => !ParsingHelper.IsResourceKeyAttribute(x)))
                        {
                            resource.Properties.Add(attribute.LocalName, attribute.Value);
                        }
                        result.Add(resource);
                    }
                }
            }
            else
            {
                throw new Exception("Global resource files which do not start with a resource tag");
            }

            return(result);
        }