private static bool TryParseClassification( JObject jObject, out ClassificationSettings classification, out IReadOnlyDictionary <string, object> properties) { if (!jObject.TryGetProperty(nameof(ClassificationSettings.Name), out string name)) { classification = default; properties = _emptyProperties; return(false); } classification = new ClassificationSettings { Name = name }; if (jObject.TryGetProperty(nameof(classification.Background), out string background) && background.TryParseColor(out Color color)) { classification.Background = color; } if (jObject.TryGetProperty(nameof(classification.Foreground), out string foreground) && foreground.TryParseColor(out color)) { classification.Foreground = color; } if (jObject.TryGetProperty(nameof(classification.FontFamily), out string fontFamily)) { classification.FontFamily = fontFamily; } if (jObject.TryGetProperty(nameof(classification.FontStyle), out string fontStyle)) { classification.FontStyle = fontStyle; } if (jObject.TryGetProperty(nameof(classification.FontStretch), out long fontStretch) && fontStretch < 10) { classification.FontStretch = (int)fontStretch; } if (jObject.TryGetProperty(nameof(classification.FontRenderingSize), out long renderingSize) && renderingSize < 512) { classification.FontRenderingSize = (int)renderingSize; } classification.IsBold = jObject.GetPropertyValue <bool>(nameof(classification.IsBold)); classification.IsOverline = jObject.GetPropertyValue <bool>(nameof(classification.IsOverline)); classification.IsUnderline = jObject.GetPropertyValue <bool>(nameof(classification.IsUnderline)); classification.IsStrikethrough = jObject.GetPropertyValue <bool>(nameof(classification.IsStrikethrough)); classification.IsBaseline = jObject.GetPropertyValue <bool>(nameof(classification.IsBaseline)); classification.IsDisabled = jObject.GetPropertyValue <bool>(nameof(classification.IsDisabled)); classification.IsDisabledInEditor = jObject.GetPropertyValue <bool>(nameof(classification.IsDisabledInEditor)); classification.IsDisabledInQuickInfo = jObject.GetPropertyValue <bool>(nameof(classification.IsDisabledInQuickInfo)); classification.IsDisabledInXml = jObject.GetPropertyValue <bool>(nameof(classification.IsDisabledInXml)); properties = jObject.GetProperties(); return(true); }
private static JObject ToJObject(ClassificationSettings classification) { var jClassification = new JObject(); jClassification.Add(nameof(classification.Name), new JValue(classification.Name)); if (classification.Background.HasValue) { jClassification.Add(nameof(classification.Background), new JValue(classification.Background.Value.ToString())); } if (classification.Foreground.HasValue) { jClassification.Add(nameof(classification.Foreground), new JValue(classification.Foreground.Value.ToString())); } if (!string.IsNullOrWhiteSpace(classification.FontFamily)) { jClassification.Add(nameof(classification.FontFamily), new JValue(classification.FontFamily)); } if (!string.IsNullOrWhiteSpace(classification.FontStyle)) { jClassification.Add(nameof(classification.FontStyle), new JValue(classification.FontStyle)); } jClassification .AppendProperty(nameof(classification.IsBold), classification.IsBold) .AppendProperty(nameof(classification.FontStretch), classification.FontStretch) .AppendProperty(nameof(classification.IsOverline), classification.IsOverline) .AppendProperty(nameof(classification.IsUnderline), classification.IsUnderline) .AppendProperty(nameof(classification.IsStrikethrough), classification.IsStrikethrough) .AppendProperty(nameof(classification.IsBaseline), classification.IsBaseline) .AppendProperty(nameof(classification.FontRenderingSize), classification.FontRenderingSize) .AppendProperty(nameof(classification.IsDisabled), classification.IsDisabled) .AppendProperty(nameof(classification.IsDisabledInEditor), classification.IsDisabledInEditor) .AppendProperty(nameof(classification.IsDisabledInQuickInfo), classification.IsDisabledInQuickInfo) .AppendProperty(nameof(classification.IsDisabledInXml), classification.IsDisabledInXml); return(jClassification); }