Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.Map<String, Object> readMap(final String input, String... requiredKeys) throws org.neo4j.server.rest.repr.BadInputException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override IDictionary <string, object> ReadMap(string input, params string[] requiredKeys)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (input.Length == 0)
            {
                return(result);
            }

            foreach (string pair in input.Split("&", true))
            {
                string[] fields = pair.Split("=", true);
                string   key;
                string   value;

                try
                {
                    string charset = StandardCharsets.UTF_8.name();
                    key   = EnsureThatKeyDoesNotHavePhPStyleParenthesesAtTheEnd(URLDecoder.decode(fields[0], charset));
                    value = URLDecoder.decode(fields[1], charset);
                }
                catch (UnsupportedEncodingException e)
                {
                    throw new BadInputException(e);
                }

                object old = result[key];
                if (old == null)
                {
                    result[key] = value;
                }
                else
                {
                    IList <object> list;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (old instanceof java.util.List<?>)
                    if (old is IList <object> )
                    {
                        list = (IList <object>)old;
                    }
                    else
                    {
                        list        = new List <object>();
                        result[key] = list;
                        list.Add(old);
                    }
                    list.Add(value);
                }
            }

            return(DefaultFormat.validateKeys(result, requiredKeys));
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.Map<String, Object> readMap(String input, String... requiredKeys) throws org.neo4j.server.rest.repr.BadInputException
        public override IDictionary <string, object> ReadMap(string input, params string[] requiredKeys)
        {
            if (Empty(input))
            {
                return(DefaultFormat.validateKeys(Collections.emptyMap(), requiredKeys));
            }
            try
            {
                return(DefaultFormat.validateKeys(JsonHelper.jsonToMap(StripByteOrderMark(input)), requiredKeys));
            }
            catch (Exception ex)
            {
                throw new BadInputException(ex);
            }
        }