Пример #1
0
        private void DeserializeComponent(Component component, JObject json)
        {
            var lineInfo = json as IJsonLineInfo;
            if (lineInfo != null && lineInfo.HasLineInfo())
                component.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);

            foreach (var jprop in json.Properties().Where(x =>
                !x.Name.StartsWith("$") && x.HasValues && x.Value.Type != JTokenType.Object))
            {
                var jvalue = jprop.Value as JValue;
                if (jvalue != null)
                {
                    var value = jvalue.Value;
                    var str = value as string;
                    Guid guid;
                    // See if it's a Guid.
                    if (str != null && str.StartsWith("{") && str.EndsWith("}") &&
                        Guid.TryParse(str, out guid))
                    {
                        value = guid;
                    }

                    var property = component.CreateProperty(jprop.Name);
                    property.Value = value;

                    lineInfo = jvalue as IJsonLineInfo;
                    if (lineInfo != null && lineInfo.HasLineInfo())
                        property.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);
                }
            }
        }