DotNetWebToolkit.Server.JsonTypeMap.FromString C# (CSharp) Method

FromString() public static method

public static FromString ( string s ) : JsonTypeMap
s string
return JsonTypeMap
        public static JsonTypeMap FromString(string s) {
            var lines = s.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var typeNames = new Dictionary<string, string>();
            var fieldNames = new Dictionary<string, Dictionary<string, string>>();
            int i;
            for (i = 0; lines[i] != ""; i++) {
                var line = lines[i];
                var data = line.Split(':');
                typeNames.Add(data[0], data[1]);
            }
            i++;
            while (i < lines.Length) {
                var type = lines[i];
                i++;
                var fields = new Dictionary<string, string>();
                while (i < lines.Length && lines[i].StartsWith(" ")) {
                    var data = lines[i].Substring(1).Split(':');
                    fields.Add(data[0], data[1]);
                    i++;
                }
                fieldNames.Add(type, fields);
            }
            return new JsonTypeMap(typeNames, fieldNames);
        }

Usage Example

Beispiel #1
0
        public static Json FromFile(string path)
        {
            var s       = File.ReadAllText(path);
            var typeMap = JsonTypeMap.FromString(s);

            return(new Json(typeMap));
        }