コード例 #1
0
ファイル: ElementDescriptor.cs プロジェクト: Xtremrules/dot42
 /// <summary>
 /// Add the given attribute as possible attribute for this element if no other attribute with same name exists.
 /// </summary>
 internal bool Add(AttributeDescriptor attribute)
 {
     if (!attributes.ContainsKey(attribute.Name))
     {
         attributes[attribute.Name] = attribute;
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: AttrsXmlParser.cs プロジェクト: Xtremrules/dot42
        /// <summary>
        /// Parse an attr element into an <see cref="AttributeDescriptor"/>.
        /// </summary>
        private AttributeDescriptor ParseAttr(XElement attr)
        {
            var name = GetName(attr);
            var formatAsString = GetFormat(attr);
            if (string.IsNullOrEmpty(formatAsString))
            {
                // Auto detect format
                if (attr.Elements("enum").Any())
                    formatAsString = "enum";
                else if (attr.Elements("flag").Any())
                    formatAsString = "flag";
            }

            // Try to parse the format string
            var format = ParseFormat(formatAsString);

            // If not available, try R.attr
            AttributeDescriptor result = null;
            if ((format == 0) && (AttrTypeSpec != null))
            {
                // Detect format from R.attr
                var entry = AttrTypeSpec.Entries.FirstOrDefault(x => x.Key == name);
                if (entry != null)
                {
                    var anyType = AttrTypeSpec.Types.FirstOrDefault(x => x.Configuration.IsAny);
                    if (anyType != null)
                    {
                        Table.EntryInstance instance;
                        Table.ComplexEntryInstance cInstance;
                        if (entry.TryGetInstance(anyType, out instance) &&
                            ((cInstance = instance as Table.ComplexEntryInstance) != null))
                        {
                            AttributeTypes attributeType;
                            if (cInstance.TryGetAttributeType(out attributeType))
                            {
                                // We've found it
                                format = AttributeTypeToFormat(attributeType);

                                // Instantiate descriptor
                                result = new AttributeDescriptor(name, format);
                                if (((attributeType & AttributeTypes.TYPE_ENUM) != 0) ||
                                    ((attributeType & AttributeTypes.TYPE_FLAGS) != 0))
                                {
                                    // Get enum/flag values from resources.arsc
                                    foreach (var value in cInstance.GetEnumOrFlagValueNames())
                                    {
                                        result.Add(new AttributeValueDescriptor(value));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Instantiate descriptor
            result = result ?? new AttributeDescriptor(name, format);
            foreach (var child in attr.Elements("enum"))
            {
                result.Add(new AttributeValueDescriptor(GetName(child)));
            }
            foreach (var child in attr.Elements("flag"))
            {
                result.Add(new AttributeValueDescriptor(GetName(child)));
            }
            return result;
        }
コード例 #3
0
 /// <summary>
 /// Create completions for attribute names.
 /// </summary>
 private IEnumerable<XmlResourceCompletion> CreateAttributeValueCompletions(AttributeDescriptor attributeDescriptor)
 {
     var provider = DescriptorProvider;
     if (provider == null)
         return Enumerable.Empty<XmlResourceCompletion>();
     var names = attributeDescriptor.StandardValues.Select(x => x.Value);
     return names.OrderBy(x => x).Select(x => new XmlResourceCompletion(glyphService, x, x, x, -1, XmlResourceCompletionType.Attribute));
 }
コード例 #4
0
ファイル: AttrsXmlParser.cs プロジェクト: yuva2achieve/dot42
        /// <summary>
        /// Parse an attr element into an <see cref="AttributeDescriptor"/>.
        /// </summary>
        private AttributeDescriptor ParseAttr(XElement attr)
        {
            var name           = GetName(attr);
            var formatAsString = GetFormat(attr);

            if (string.IsNullOrEmpty(formatAsString))
            {
                // Auto detect format
                if (attr.Elements("enum").Any())
                {
                    formatAsString = "enum";
                }
                else if (attr.Elements("flag").Any())
                {
                    formatAsString = "flag";
                }
            }

            // Try to parse the format string
            var format = ParseFormat(formatAsString);

            // If not available, try R.attr
            AttributeDescriptor result = null;

            if ((format == 0) && (AttrTypeSpec != null))
            {
                // Detect format from R.attr
                var entry = AttrTypeSpec.Entries.FirstOrDefault(x => x.Key == name);
                if (entry != null)
                {
                    var anyType = AttrTypeSpec.Types.FirstOrDefault(x => x.Configuration.IsAny);
                    if (anyType != null)
                    {
                        Table.EntryInstance        instance;
                        Table.ComplexEntryInstance cInstance;
                        if (entry.TryGetInstance(anyType, out instance) &&
                            ((cInstance = instance as Table.ComplexEntryInstance) != null))
                        {
                            AttributeTypes attributeType;
                            if (cInstance.TryGetAttributeType(out attributeType))
                            {
                                // We've found it
                                format = AttributeTypeToFormat(attributeType);

                                // Instantiate descriptor
                                result = new AttributeDescriptor(name, format);
                                if (((attributeType & AttributeTypes.TYPE_ENUM) != 0) ||
                                    ((attributeType & AttributeTypes.TYPE_FLAGS) != 0))
                                {
                                    // Get enum/flag values from resources.arsc
                                    foreach (var value in cInstance.GetEnumOrFlagValueNames())
                                    {
                                        result.Add(new AttributeValueDescriptor(value));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Instantiate descriptor
            result = result ?? new AttributeDescriptor(name, format);
            foreach (var child in attr.Elements("enum"))
            {
                result.Add(new AttributeValueDescriptor(GetName(child)));
            }
            foreach (var child in attr.Elements("flag"))
            {
                result.Add(new AttributeValueDescriptor(GetName(child)));
            }
            return(result);
        }