Ejemplo n.º 1
0
        // loads a natives.json from given path and returns data
        public static List<NativeNamespace> LoadFromFile(String path)
        {
            List<NativeNamespace> natives = new List<NativeNamespace>();

            String json = File.ReadAllText(path);
            JObject namespaces = JObject.Parse(json);

            // Iterate namespaces
            foreach (KeyValuePair<String, JToken> _namespace in namespaces)
            {
                // Make a new namespace
                NativeNamespace ns = new NativeNamespace()
                {
                    Name = _namespace.Key,
                    Functions = new List<NativeFunction>()
                };

                // Iterate namespace functions
                foreach (KeyValuePair<String, JToken> _function in (JObject)_namespace.Value)
                {
                    // Make a new native function
                    NativeFunction function = new NativeFunction()
                    {
                        Namespace = (String)_namespace.Key,
                        Hash = (String)_function.Key,
                        Name = (String)_function.Value["name"],
                        Result = (String)_function.Value["results"],
                        JHash = (String)_function.Value["jhash"],
                        Params = new List<FunctionParameter>()
                    };
                    // Add function parameters
                    JArray parameters = (JArray)_function.Value["params"];
                    // Add parameters
                    foreach (JObject _parameter in parameters)
                    {
                        FunctionParameter parameter = new FunctionParameter()
                        {
                            Name = _parameter.Value<String>("name"),
                            Type = _parameter.Value<String>("type")
                        };
                        function.Params.Add(parameter);
                    }

                    ns.Functions.Add(function);
                }

                natives.Add(ns);
            }

            return natives;
        }
Ejemplo n.º 2
0
        // Search in natives by name
        List<NativeFunction> SearchByName(NativeNamespace ns, String filter)
        {
            if (natives == null) return null;

            List<NativeFunction> found = new List<NativeFunction>();

            foreach (NativeFunction _function in ns.Functions)
            {
                if (_function.Name.Contains(filter))
                    found.Add(_function);
            }

            return found;
        }