Only support PropertyListObjectModel and throw ObjectModelNotSupportedException if we get something else

This commit is contained in:
Michael Becker 2014-06-08 20:41:46 -04:00
parent f9a4f7c2a3
commit 0eb0ca3a8a

View File

@ -31,58 +31,57 @@ namespace UniversalEditor.DataFormats.PropertyList
protected override void LoadInternal(ref ObjectModel objectModel)
{
PropertyListObjectModel plom = objectModel as PropertyListObjectModel;
PropertyListObjectModel plom = (objectModel as PropertyListObjectModel);
if (plom == null) throw new ObjectModelNotSupportedException();
Reader tr = base.Accessor.Reader;
Group CurrentGroup = null;
if (objectModel is PropertyListObjectModel)
while (!tr.EndOfStream)
{
PropertyListObjectModel objm = objectModel as PropertyListObjectModel;
while (!tr.EndOfStream)
{
string line = tr.ReadLine();
if (String.IsNullOrEmpty(line)) continue;
string line = tr.ReadLine();
if (String.IsNullOrEmpty(line)) continue;
if (!line.StartsWith(";") && !line.StartsWith("#"))
if (!line.StartsWith(";") && !line.StartsWith("#"))
{
if (line.StartsWith("[") && line.EndsWith("]"))
{
if (line.StartsWith("[") && line.EndsWith("]"))
string groupName = line.Substring(1, line.Length - 2);
CurrentGroup = plom.Groups.Add(groupName);
}
else
{
if (line.Contains(mvarPropertyNameValueSeparator))
{
string groupName = line.Substring(1, line.Length - 2);
CurrentGroup = plom.Groups.Add(groupName);
}
else
{
if (line.Contains(mvarPropertyNameValueSeparator))
string[] nvp = line.Split(new string[]
{
string[] nvp = line.Split(new string[]
mvarPropertyNameValueSeparator
}, 2, StringSplitOptions.None);
string propertyName = nvp[0].Trim();
string propertyValue = string.Empty;
if (nvp.Length == 2)
{
propertyValue = nvp[1].Trim();
}
if (propertyValue.StartsWith(this.mvarPropertyValuePrefix) && propertyValue.EndsWith(this.mvarPropertyValueSuffix))
{
propertyValue = propertyValue.Substring(this.mvarPropertyValuePrefix.Length, propertyValue.Length - this.mvarPropertyValuePrefix.Length - this.mvarPropertyValueSuffix.Length);
}
else
{
if (propertyValue.ContainsAny(this.mvarCommentSignals))
{
mvarPropertyNameValueSeparator
}, 2, StringSplitOptions.None);
string propertyName = nvp[0].Trim();
string propertyValue = string.Empty;
if (nvp.Length == 2)
{
propertyValue = nvp[1].Trim();
}
if (propertyValue.StartsWith(this.mvarPropertyValuePrefix) && propertyValue.EndsWith(this.mvarPropertyValueSuffix))
{
propertyValue = propertyValue.Substring(this.mvarPropertyValuePrefix.Length, propertyValue.Length - this.mvarPropertyValuePrefix.Length - this.mvarPropertyValueSuffix.Length);
}
else
{
if (propertyValue.ContainsAny(this.mvarCommentSignals))
{
propertyValue = propertyValue.Substring(0, propertyValue.IndexOfAny(this.mvarCommentSignals));
}
}
if (CurrentGroup != null)
{
CurrentGroup.Properties.Add(propertyName, propertyValue);
}
else
{
plom.Properties.Add(propertyName, propertyValue);
propertyValue = propertyValue.Substring(0, propertyValue.IndexOfAny(this.mvarCommentSignals));
}
}
if (CurrentGroup != null)
{
CurrentGroup.Properties.Add(propertyName, propertyValue);
}
else
{
plom.Properties.Add(propertyName, propertyValue);
}
}
}
}