Exemple #1
0
        internal HtmlElementDefinition GetTag(string tagName)
        {
            if (tagName == null)
            {
                throw new ArgumentNullException(nameof(tagName));
            }

            tagName = tagName.Trim().ToLowerInvariant();
            if (tagName.Length == 0)
            {
                throw Failure.AllWhitespace(nameof(tagName));
            }

            // TODO This behavior causes any undefined tag to be
            // added to HTML 5 (need different behavior)

            var tags = this.ElementDefinitions;

            lock (tags) {
                var tag = (HtmlElementDefinition)tags[tagName];
                if (tag == null)
                {
                    // not defined: create default; go anywhere, do anything! (incl be inside a <p>)
                    tag = new HtmlElementDefinition(tagName);
                    tags.Add(tag);
                    tag.IsUnknownTag    = true;
                    tag.IsBlock         = false;
                    tag.CanContainBlock = true;
                }
                return(tag);
            }
        }
Exemple #2
0
        static Exception _TryParse(string text, out MethodName result)
        {
            result = null;

            if (text == null)
            {
                return(new ArgumentNullException("text")); // $NON-NLS-1
            }
            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            try {
                result = new SignatureParser(text, false, true).ParseMethod();
                return(null);
            } catch (Exception ex) {
                if (Failure.IsCriticalException(ex))
                {
                    throw;
                }
                return(Failure.NotParsable("text", typeof(MethodName)));
            }
        }
Exemple #3
0
        static Exception _TryParse(string text, TypeNameParseOptions options, out TypeName result)
        {
            result = null;

            if (text == null)
            {
                return(new ArgumentNullException("text")); // $NON-NLS-1
            }
            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            bool preferGenericParams = options.HasFlag(TypeNameParseOptions.AssumeGenericParameters);

            try {
                result = new SignatureParser(text, preferGenericParams).ParseType();
                return(null);
            } catch (Exception ex) {
                if (Failure.IsCriticalException(ex))
                {
                    throw;
                }
                return(Failure.NotParsable("text", typeof(TypeName)));
            }
        }
        static Exception _TryParse(string text,
                                   IServiceProvider serviceProvider,
                                   out TypeReference result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException("type"));
            }
            text = text.Trim();

            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            serviceProvider = serviceProvider ?? ServiceProvider.Root;

            Type builtIn;

            if (builtInNames.TryGetValue(text, out builtIn))
            {
                result = FromType(builtIn);
                return(null);
            }

            if (text.Contains(":") || text.Contains("{"))
            {
                try {
                    QualifiedName qn = QualifiedName.Parse(text, serviceProvider);
                    result = new TypeReference(text, new QualifiedNameResolver(qn));
                    return(null);
                } catch (FormatException f) {
                    return(Failure.NotParsable("text", typeof(TypeReference), f));
                }
            }

            string[] s        = text.Split(new [] { ',' }, 2);
            string   typeName = s[0];

            if (s.Length == 2)
            {
                AssemblyName assemblyName = null;
                try {
                    assemblyName = new AssemblyName(s[1]);
                } catch (Exception ex) {
                    return(Failure.NotParsable("text", typeof(TypeReference), ex));
                }

                var resolveThunk = new DefaultResolver(assemblyName, typeName);
                result = new TypeReference(text, resolveThunk);
                return(null);
            }
            else
            {
                var resolveThunk = new SlowResolver(typeName);
                result = new TypeReference(text, resolveThunk);
                return(null);
            }
        }
Exemple #5
0
        internal static Exception _TryParse(string text, out AssemblyName result)
        {
            result = null;

            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();

            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            string[] items = text.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            try {
                string name = items[0];
                if (items.Length == 1)
                {
                    result = new DefaultAssemblyName(name, null);
                    return(null);
                }

                var lookup = new Dictionary <string, string>();
                for (int i = 1; i < items.Length; i++)
                {
                    string s     = items[i];
                    int    index = s.IndexOf('=');

                    if (index < 0)
                    {
                        throw Failure.NotParsable("text", typeof(AssemblyName));
                    }

                    string key   = s.Substring(0, index).Trim();
                    string value = s.Substring(index + 1).Trim();
                    lookup.Add(key, value);
                }

                AssemblyNameBuilder builder = new AssemblyNameBuilder();
                builder.Name = name;
                Exception exception = builder.ParseDictionary(lookup);

                if (exception == null)
                {
                    result = builder.Build();
                    return(null);
                }
                return(exception);
            }

            catch (ArgumentException a) {
                return(Failure.NotParsable("text", typeof(AssemblyName), a));
            }
            catch (FormatException f) {
                return(Failure.NotParsable("text", typeof(AssemblyName), f));
            }
        }
        internal static DomPathExpression ById(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw Failure.AllWhitespace(nameof(id));
            }

            return(new IdExpr(id));
        }
Exemple #7
0
        public XmlNameSemantics(string prefix, string localName)
        {
            if (string.IsNullOrWhiteSpace(localName))
            {
                throw Failure.AllWhitespace(nameof(localName));
            }

            Prefix    = string.IsNullOrEmpty(prefix) ? null : prefix;
            LocalName = localName;
        }
Exemple #8
0
        internal static Exception ParseSimpleMember <T>(string text, out T result, Func <TypeName, string, TypeName, T> func)
        {
            result = default(T);
            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            string   name       = text;
            TypeName returnType = null;
            int      colonIndex = text.LastIndexOf(':');

            if (colonIndex >= 0)
            {
                name = text.Substring(0, colonIndex);
                if (!TypeName.TryParse(text.Substring(colonIndex + 1), out returnType))
                {
                    return(Failure.NotParsable("text", typeof(T)));
                }
            }

            TypeName type;
            int      index = name.LastIndexOf('.');

            if (index < name.Length - 1)
            {
                if (index > 0)
                {
                    if (TypeName.TryParse(name.Substring(0, index), out type))
                    {
                        string simpleName = name.Substring(index + 1);
                        result = func(type, simpleName, returnType);
                        return(null);
                    }
                }
                else
                {
                    result = func(null, name, returnType);
                    return(null);
                }
            }

            return(Failure.NotParsable("text", typeof(T)));
        }
Exemple #9
0
        private static string CheckRole(string role)
        {
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            role = role.Trim();
            if (role.Length == 0)
            {
                throw Failure.AllWhitespace(nameof(role));
            }
            return(role);
        }
Exemple #10
0
 public ModuleName Update(string name = null)
 {
     if (name == null || name == this.Name)
     {
         return(this);
     }
     else if (name.Trim().Length == 0)
     {
         throw Failure.AllWhitespace("name");
     }
     else
     {
         return(new ModuleName(name));
     }
 }
        public static Properties FromFile(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw Failure.AllWhitespace("fileName");
            }

            Properties p = new Properties();

            p.Load(fileName);
            return(p);
        }
        static Exception _TryParse(string text, out TargetArchitecture result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            result = new TargetArchitecture(text);
            return(null);
        }
Exemple #13
0
        static Exception _TryParse(string text, out SymbolTypes result)
        {
            result = null;

            if (text == null)
            {
                return(new ArgumentNullException(nameof(text)));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace(nameof(text)));
            }
            if (text == "All")
            {
                result = new SymbolTypes(true);
                return(null);
            }
            if (text == "None")
            {
                result = new SymbolTypes();
                return(null);
            }

            result = new SymbolTypes();

            foreach (var t in Utility.SplitTokens(text))
            {
                SymbolType symbol;

                if (Enum.TryParse(t, true, out symbol))
                {
                    result[symbol] = true;
                }
                else
                {
                    return(Failure.NotParsable(nameof(text), typeof(SymbolTypes)));
                }
            }

            return(null);
        }
Exemple #14
0
        static Exception _TryParse(string text, out ContentType result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();
            if (string.IsNullOrEmpty(text))
            {
                return(Failure.AllWhitespace("text"));
            }

            string[] split     = text.Split(';');
            string[] mediaType = split[0].Split('/');
            result = new ContentType(mediaType[0],
                                     mediaType[1],
                                     ParseParameters(split.Skip(1)));

            return(null);
        }
Exemple #15
0
        static Exception _TryParse(string text, out CodeReference result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException("text")); // $NON-NLS-1
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("name")); // $NON-NLS-1
            }

            int index = text.IndexOf(':');

            if (index < 0)
            {
                result = new UnspecifiedCodeReference(text);
                return(null);
            }

            string specifier = text.Substring(0, index).Trim();
            string name      = text.Substring(index + 1).Trim();

            if (specifier.Length == 1)
            {
                SymbolType type = CodeReferenceHelper.GetReferenceType(specifier[0]);

                if (type != SymbolType.Unknown)
                {
                    result = Create(type, name);
                    return(result.IsValid ? null : Failure.NotParsable("text", typeof(CodeReference)));
                }
            }

            return(Failure.NotParsable("text", typeof(CodeReference)));
        }
Exemple #16
0
        private static Exception _TryParse(string text, out CssSelector result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException(nameof(text)));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace(nameof(text)));
            }

            try {
                var opts      = new QueryParserOptions();
                var evaluator = QueryParser.Parse(text, opts);
                result = new CssSelector(evaluator);
                return(null);
            } catch (Exception ex) {
                return(Failure.NotParsable(nameof(text), typeof(CssSelector), ex));
            }
        }
Exemple #17
0
        static Exception _TryParse(string text, out ModuleName result)
        {
            result = null;
            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            // TODO Verify which characters are considered valid
            if (Regex.IsMatch(text, @"\w+(\.\w+)*"))
            {
                result = new ModuleName(text);
                return(null);
            }

            return(Failure.NotParsable("text", typeof(ModuleName)));
        }
Exemple #18
0
        static Exception _TryParse(string text, out PropertyName result)
        {
            result = default(PropertyName);
            if (text == null)
            {
                return(new ArgumentNullException("text"));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace("text"));
            }

            try {
                result = new SignatureParser(text).ParseProperty();
            } catch {
            }
            if (result == null)
            {
                return(Failure.NotParsable("text", typeof(PropertyName)));
            }
            return(null);
        }
        private static Exception _TryParse(string text, out DomWhitespaceMode result)
        {
            result = default(DomWhitespaceMode);
            if (text == null)
            {
                return(new ArgumentNullException(nameof(text)));
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                return(Failure.AllWhitespace(nameof(text)));
            }

            var  existing = Array.FindIndex(_allValues, m => m._name == text);
            bool exists   = existing >= 0;

            if (exists)
            {
                result = _allValues[existing];
                return(null);
            }
            return(Failure.NotParsable(nameof(text), typeof(DomWhitespaceMode)));
        }
        internal static LoggerLevel _TryParse(string text, bool throwError)
        {
            if (text == null)
            {
                if (throwError)
                {
                    throw new ArgumentNullException("text");
                }
                else
                {
                    return(null);
                }
            }

            if (text.Length == 0)
            {
                if (throwError)
                {
                    throw Failure.EmptyString("text");
                }
                else
                {
                    return(null);
                }
            }

            text = text.Trim();
            if (text.Length == 0)
            {
                if (throwError)
                {
                    throw Failure.AllWhitespace("text");
                }
                else
                {
                    return(null);
                }
            }

            switch (text.ToLowerInvariant())
            {
            case "off":
                return(LoggerLevel.Off);

            case "debug":
                return(LoggerLevel.Debug);

            case "trace":
                return(LoggerLevel.Trace);

            case "info":
                return(LoggerLevel.Info);

            case "warn":
                return(LoggerLevel.Warn);

            case "error":
                return(LoggerLevel.Error);

            case "fatal":
                return(LoggerLevel.Fatal);

            case "verbose":
                return(LoggerLevel.Verbose);
            }

            if (throwError)
            {
                throw Failure.NotParsable("text", typeof(LoggerLevel));
            }
            else
            {
                return(null);
            }
        }