Esempio n. 1
0
        internal void ReplaceWith(string path, JsonTemplate replacement)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new Exception("根路径不适合于替换子模板的导航");
            }
            int    indexOfDot     = path.IndexOf('.');
            string currentLocator = indexOfDot < 0 ? path : path.Substring(0, indexOfDot);
            string restLocator    = indexOfDot < 0 ? string.Empty : path.Substring(indexOfDot + 1);

            if (ValueType == ValueType.Object)
            {
                if (!ObjectProperties.ContainsKey(currentLocator))
                {
                    throw new Exception($"路径是错误的,当前成员不包含{currentLocator}属性");
                }
                if (string.IsNullOrWhiteSpace(restLocator))
                {
                    //将替换为对象元素
                    ObjectProperties[currentLocator] = replacement;
                }
                else
                {
                    ObjectProperties[currentLocator].ReplaceWith(restLocator, replacement);
                }
            }
            else
            {
                throw new Exception($"{ValueType.ToString()}没有成员可以替换");
            }
        }
Esempio n. 2
0
        public PrimetonDescriptorViewModel()
        {
            InputBody           = new JsonTemplate();
            InputBody.ValueType = ValueType.Object;
            InputBody.IsArray   = false;

            ReturnBody           = new JsonTemplate();
            ReturnBody.ValueType = ValueType.Object;
            ReturnBody.IsArray   = false;
            ReturnBody.ObjectProperties.Add("flag", JsonTemplate.Create(ValueType.String, false));
            ReturnBody.ObjectProperties.Add("msg", JsonTemplate.Create(ValueType.String, false));
        }
Esempio n. 3
0
 public EditServiceJsonViewModel(EditServiceJson serviceJson)
 {
     //ServiceType = serviceJson.ServiceType;
     ServiceDescriptor = serviceJson.ServiceDescriptor;
     CurrentName       = serviceJson.CurrentName;
     CurrentPath       = serviceJson.CurrentPath;
     CurrentJson       = serviceJson.CurrentJson;
     if (string.IsNullOrWhiteSpace(serviceJson.CurrentJson))
     {
         CurrentTemplate           = new JsonTemplate();
         CurrentTemplate.ValueType = ValueType.Integer;
     }
     else
     {
         CurrentTemplate = JsonConvert.DeserializeObject <JsonTemplate>(serviceJson.CurrentJson);
     }
 }