private void ParseImportDeclarations()
 {
     for (int i = 0; i < File.Count; i++)
     {
         int               lineIndexer       = i;
         string            line              = File[i];
         ImportDeclaration importDeclaration = null;
         try
         {
             if (line.Contains("Imports"))
             {
                 importDeclaration = new ImportDeclaration(lineIndexer, line);
             }
             else
             {
                 continue;
             }
         }
         catch (InvalidOperationException)
         {
             continue;
         }
         DeclaredNamespaces.Add(importDeclaration);
     }
 }
예제 #2
0
 public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax Node)
 {
     base.VisitNamespaceDeclaration(Node);
     DeclaredNamespaces.Add(Node.Name.ToString());
 }
예제 #3
0
        internal void Save(SavingContext ctx)
        {
            // First we need to write the namespaces declared within this element
            foreach (KeyValuePair <string, Uri> pair in DeclaredNamespaces)
            {
                ctx.Writer.WriteChunkHeader(ResourceType.XmlStartNamespace, 16); // Each namespace tag is 3 integers, so 3 * 4 = 12 bytes
                ctx.Writer.Write(TextLineNumber);
                ctx.Writer.Write(0xFFFFFFFF);
                ctx.Writer.Write(ctx.StringPool.GetIndex(pair.Key));
                ctx.Writer.Write(ctx.StringPool.GetIndex(pair.Value.ToString()));
            }

            ctx.Writer.WriteChunkHeader(ResourceType.XmlStartElement, 28 + 20 * Attributes.Count); // Each attribute is 5 integers, so 5 * 4 = 20 bytes of the tag
            ctx.Writer.Write(TextLineNumber);
            ctx.Writer.Write(0xFFFFFFFF);
            ctx.Writer.Write(NamespaceUri == null ? -1 : ctx.StringPool.GetIndex(NamespaceUri.ToString()));
            ctx.Writer.Write(ctx.StringPool.GetIndex(Name));
            ctx.Writer.Write(0x00140014);

            // Find the ID, class and style attribute indices if they exist
            short idAttributeIndex    = -1;
            short classAttributeIndex = -1;
            short styleAttributeIndex = -1;

            for (short i = 0; i < Attributes.Count; i++)
            {
                WrappedValue?wrappedValue = Attributes[i].Value as WrappedValue;
                if (wrappedValue == null)
                {
                    continue;
                }

                // Make sure to prevent multiple of these attributes, as this will save incorrectly
                switch (wrappedValue.Type)
                {
                case WrappedValueType.Id:
                    if (idAttributeIndex != -1)
                    {
                        throw new InvalidDataException("Cannot have multiple ID attributes on one element");
                    }
                    idAttributeIndex = i;
                    break;

                case WrappedValueType.Class:
                    if (classAttributeIndex != -1)
                    {
                        throw new InvalidDataException("Cannot have multiple class attributes on one element");
                    }
                    classAttributeIndex = i;
                    break;

                case WrappedValueType.Style:
                    if (styleAttributeIndex != -1)
                    {
                        throw new InvalidDataException("Cannot have multiple style attributes on one element");
                    }
                    styleAttributeIndex = i;
                    break;
                }
            }

            ctx.Writer.Write((short)Attributes.Count);
            // Stored indices are one above the actual ones
            ctx.Writer.Write((short)(idAttributeIndex + 1));
            ctx.Writer.Write((short)(classAttributeIndex + 1));
            ctx.Writer.Write((short)(styleAttributeIndex + 1));
            foreach (AxmlAttribute attribute in Attributes)
            {
                attribute.Save(ctx);
            }

            foreach (AxmlElement child in Children)
            {
                child.Save(ctx);
            }
            ctx.Writer.WriteChunkHeader(ResourceType.XmlEndElement, 16);
            ctx.Writer.Write(-1);
            ctx.Writer.Write(0xFFFFFFFF);
            ctx.Writer.Write(NamespaceUri == null ? -1 : ctx.StringPool.GetIndex(NamespaceUri.ToString()));
            ctx.Writer.Write(ctx.StringPool.GetIndex(Name));

            // End the namespaces stated by this element, as we have exited it
            foreach (KeyValuePair <string, Uri> pair in DeclaredNamespaces.Reverse())
            {
                ctx.Writer.WriteChunkHeader(ResourceType.XmlEndNamespace, 16); // Each namespace tag is 3 integers, so 3 * 4 = 12 bytes
                ctx.Writer.Write(TextLineNumber);
                ctx.Writer.Write(0xFFFFFFFF);
                ctx.Writer.Write(ctx.StringPool.GetIndex(pair.Key));
                ctx.Writer.Write(ctx.StringPool.GetIndex(pair.Value.ToString()));
            }
        }
 private bool IsNamespaceDeclared()
 {
     return(DeclaredNamespaces.Any(d => d == ImportDeclaration));
 }