Пример #1
0
        public JObjectViewModel(JObject jObject, JsonViewModelFactory jsonViewModelFactory)
        {
            JToken = jObject;
            var id = jObject.Properties().SingleOrDefault(x => x.Name.ToLowerInvariant() == "id")?.Value.ToString()
                     ?? jObject.Properties().SingleOrDefault(x => x.Name.ToLowerInvariant() == "_id")?.Value.ToString()
                     ?? jObject.Properties().FirstOrDefault(x => x.Name.EndsWith("Id"))?.Value.ToString()
                     ?? "(no ID)";

            Name     = id;
            Children = jObject.Properties()
                       .Select(jsonViewModelFactory.Create)
                       .ToList();
        }
Пример #2
0
        public JPropertyViewModel(
            JProperty jProperty,
            JsonViewModelFactory jsonViewModelFactory,
            IClipboard clipboard,
            ICollectionSwitcher collectionSwitcher)
        {
            JToken                  = jProperty;
            this.clipboard          = clipboard;
            this.collectionSwitcher = collectionSwitcher;
            Name = jProperty.Name;
            var referenceMatch = Regex.Match(Name, "^(?<ReferenceCollection>.+)(Id|ID)$");

            IsReference          = referenceMatch.Success;
            ReferencedCollection = DetermineReferencedCollection(referenceMatch);
            if (jProperty.Value.HasValues)
            {
                Value = string.Empty;
                if (jProperty.Value.Type == JTokenType.Array)
                {
                    Children = jProperty.Value.Children()
                               .Select(jsonViewModelFactory.Create)
                               .Where(vm => vm != null)
                               .ToList();
                }
                else if (jProperty.Value.Type == JTokenType.Object)
                {
                    Children = ((JObject)jProperty.Value)
                               .Children()
                               .Select(jsonViewModelFactory.Create)
                               .ToList();
                }
            }
            else
            {
                Value    = jProperty.Value.ToString();
                Children = new List <IJsonViewModel>();
            }
            CopyNameCommand      = new RelayCommand(CopyNameToClipboard);
            CopyValueCommand     = new RelayCommand(CopyValueToClipboard);
            OpenReferenceCommand = new RelayCommand(OpenReference, () => IsReference);
        }