Exemple #1
0
        void SetSubtype(WebSubtype type, AspNetDirective directive, List <Error> errors)
        {
            if (Subtype != WebSubtype.None)
            {
                errors.Add(new Error(ErrorType.Error, "Unexpected directive " + directive.Name.FullName, directive.Region));
                return;
            }

            Subtype = type;

            InheritedClass = GetAttributeValueCI(directive.Attributes, "inherits");
            if (ClassName == null)
            {
                ClassName = GetAttributeValueCI(directive.Attributes, "classname");
            }
            CodeBehindFile = GetAttributeValueCI(directive.Attributes, "codebehind");
            Language       = GetAttributeValueCI(directive.Attributes, "language");
            CodeFile       = GetAttributeValueCI(directive.Attributes, "codefile");
        }
        AspNetDirective GetRegisterInsertionPointNode()
        {
            foreach (XNode node in Doc.XDocument.AllDescendentNodes)
            {
                if (node is AspNetDirective)
                {
                    AspNetDirective directive = node as AspNetDirective;

                    switch (directive.Name.Name.ToLower())
                    {
                    case "page":
                    case "control":
                    case "master":
                    case "register":
                        return(directive);
                    }
                }
                else if (node is XElement)
                {
                    return(null);
                }
            }
            return(null);
        }
Exemple #3
0
        void HandleDirective(AspNetDirective directive, List <Error> errors)
        {
            switch (directive.Name.Name.ToLowerInvariant())
            {
            case "page":
                MasterPageFile = GetAttributeValueCI(directive.Attributes, "masterpagefile");
                SetSubtype(WebSubtype.WebForm, directive, errors);
                break;

            case "control":
                SetSubtype(WebSubtype.WebControl, directive, errors);
                break;

            case "webservice":
                SetSubtype(WebSubtype.WebService, directive, errors);
                break;

            case "webhandler":
                SetSubtype(WebSubtype.WebHandler, directive, errors);
                break;

            case "application":
                SetSubtype(WebSubtype.Global, directive, errors);
                break;

            case "master":
                SetSubtype(WebSubtype.MasterPage, directive, errors);
                break;

            case "mastertype":
                if (MasterPageTypeVPath != null || MasterPageTypeName != null)
                {
                    errors.Add(new Error(ErrorType.Error, "Unexpected second mastertype directive", directive.Region));
                    return;
                }
                MasterPageTypeName  = GetAttributeValueCI(directive.Attributes, "typename");
                MasterPageTypeVPath = GetAttributeValueCI(directive.Attributes, "virtualpath");
                if (string.IsNullOrEmpty(MasterPageTypeName) == string.IsNullOrEmpty(MasterPageTypeVPath))
                {
                    errors.Add(new Error(
                                   ErrorType.Error,
                                   "Mastertype directive must have non-empty 'typename' or 'virtualpath' attribute",
                                   directive.Region
                                   )
                               );
                }
                break;

            case "register":
                string tagPrefix = GetAttributeValueCI(directive.Attributes, "tagprefix");
                string tagName   = GetAttributeValueCI(directive.Attributes, "tagname");
                string src       = GetAttributeValueCI(directive.Attributes, "src");
                string nspace    = GetAttributeValueCI(directive.Attributes, "namespace");
                string assembly  = GetAttributeValueCI(directive.Attributes, "assembly");
                if (!string.IsNullOrEmpty(tagPrefix))
                {
                    if (!string.IsNullOrEmpty(tagName) && !string.IsNullOrEmpty(src))
                    {
                        registeredTags.Add(new ControlRegisterDirective(tagPrefix, tagName, src));
                    }
                    else if (!string.IsNullOrEmpty(nspace) && !string.IsNullOrEmpty(assembly))
                    {
                        registeredTags.Add(new AssemblyRegisterDirective(tagPrefix, nspace, assembly));
                    }
                }
                break;

            case "assembly":
                var assm = new AssemblyDirective(
                    GetAttributeValueCI(directive.Attributes, "name"),
                    GetAttributeValueCI(directive.Attributes, "src"));
                if (assm.IsValid())
                {
                    assemblies.Add(assm);
                }
                else
                {
                    errors.Add(new Error(
                                   ErrorType.Error,
                                   "Assembly directive must have non-empty 'name' or 'src' attribute",
                                   directive.Region
                                   )
                               );
                }
                break;

            case "import":
                string ns = GetAttributeValueCI(directive.Attributes, "namespace");
                if (!string.IsNullOrEmpty(ns))
                {
                    imports.Add(ns);
                }
                else
                {
                    errors.Add(new Error(
                                   ErrorType.Error,
                                   "Import directive must have non-empty 'namespace' attribute",
                                   directive.Region
                                   )
                               );
                }
                break;

            case "implements":
                string interf = GetAttributeValueCI(directive.Attributes, "interface");
                if (!string.IsNullOrEmpty(interf))
                {
                    implements.Add(interf);
                }
                else
                {
                    errors.Add(new Error(
                                   ErrorType.Error,
                                   "Implements directive must have non-empty 'interface' attribute",
                                   directive.Region
                                   )
                               );
                }
                break;

            default:
                break;
            }
        }