Added NameValuePair/NameValuePairGroup
This commit is contained in:
parent
885b6820b1
commit
e306842d6b
120
CSharp/Plugins/UniversalEditor.Essential/NameValuePair.cs
Normal file
120
CSharp/Plugins/UniversalEditor.Essential/NameValuePair.cs
Normal file
@ -0,0 +1,120 @@
|
||||
namespace UniversalEditor
|
||||
{
|
||||
using System;
|
||||
|
||||
public class NameValuePair : NameValuePair<string>
|
||||
{
|
||||
public NameValuePair(string Name) : base(Name)
|
||||
{
|
||||
}
|
||||
|
||||
public NameValuePair(string Name, string Value) : base(Name, Value)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class NameValuePair<T> : ICloneable
|
||||
{
|
||||
private string mvarName;
|
||||
private T mvarValue;
|
||||
|
||||
public NameValuePair(string Name)
|
||||
{
|
||||
this.mvarName = "";
|
||||
this.mvarValue = default(T);
|
||||
this.mvarName = Name;
|
||||
this.mvarValue = default(T);
|
||||
}
|
||||
|
||||
public NameValuePair(string Name, T Value)
|
||||
{
|
||||
this.mvarName = "";
|
||||
this.mvarValue = default(T);
|
||||
this.mvarName = Name;
|
||||
this.mvarValue = Value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mvarName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mvarValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class NameValuePairCollection : System.Collections.ObjectModel.Collection<NameValuePair<T>>
|
||||
{
|
||||
public NameValuePair<T> Add(string Name)
|
||||
{
|
||||
return this.Add(Name, default(T));
|
||||
}
|
||||
|
||||
public NameValuePair<T> Add(string Name, T Value)
|
||||
{
|
||||
NameValuePair<T> p = new NameValuePair<T>(Name, Value);
|
||||
base.Add(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
public bool Contains(string Name)
|
||||
{
|
||||
return (this[Name] != null);
|
||||
}
|
||||
|
||||
public bool Remove(string Name)
|
||||
{
|
||||
NameValuePair<T> p = this[Name];
|
||||
if (p != null)
|
||||
{
|
||||
base.Remove(p);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public NameValuePair<T> this[string Name]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (NameValuePair<T> p in this)
|
||||
{
|
||||
if (p.Name == Name)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
NameValuePair<T> clone = new NameValuePair<T>(mvarName.Clone() as string);
|
||||
if (mvarValue is ICloneable)
|
||||
{
|
||||
clone.Value = (T)((mvarValue as ICloneable).Clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
clone.Value = mvarValue;
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
202
CSharp/Plugins/UniversalEditor.Essential/NameValuePairGroup.cs
Normal file
202
CSharp/Plugins/UniversalEditor.Essential/NameValuePairGroup.cs
Normal file
@ -0,0 +1,202 @@
|
||||
namespace UniversalEditor
|
||||
{
|
||||
using System;
|
||||
|
||||
public class NameValuePairGroup<T>
|
||||
{
|
||||
private NameValuePairGroupCollection mvarGroups;
|
||||
private NameValuePair<T>.NameValuePairCollection mvarItems;
|
||||
private string mvarName;
|
||||
private string mvarPathSeparator;
|
||||
|
||||
public NameValuePairGroup(string Name)
|
||||
{
|
||||
mvarGroups = new NameValuePairGroupCollection();
|
||||
mvarItems = new NameValuePair<T>.NameValuePairCollection();
|
||||
mvarPathSeparator = "";
|
||||
mvarName = Name;
|
||||
}
|
||||
|
||||
public NameValuePairGroup<T> GetGroup(string GroupName)
|
||||
{
|
||||
string[] path = GroupName.Split(new string[] { this.mvarPathSeparator }, StringSplitOptions.None);
|
||||
if (path.Length == 1)
|
||||
{
|
||||
return this.mvarGroups[path[0]];
|
||||
}
|
||||
NameValuePairGroup<T> pgParent = this.mvarGroups[path[0]];
|
||||
int i = 1;
|
||||
while (pgParent != null)
|
||||
{
|
||||
if (pgParent.Groups[path[i]] != null)
|
||||
{
|
||||
pgParent = pgParent.Groups[path[i]];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pgParent.Groups[path[path.Length - 1]];
|
||||
}
|
||||
|
||||
public NameValuePair<T> GetItem(string PropertyName)
|
||||
{
|
||||
string[] path = PropertyName.Split(new string[] { this.mvarPathSeparator }, StringSplitOptions.None);
|
||||
if (path.Length == 1)
|
||||
{
|
||||
return mvarItems[path[0]];
|
||||
}
|
||||
NameValuePairGroup<T> pgParent = mvarGroups[path[0]];
|
||||
int i = 1;
|
||||
while (pgParent != null)
|
||||
{
|
||||
if (pgParent.Groups[path[i]] != null)
|
||||
{
|
||||
pgParent = pgParent.Groups[path[i]];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pgParent.Items[path[path.Length - 1]];
|
||||
}
|
||||
|
||||
public bool GetItemValueAsBoolean(string ValueName)
|
||||
{
|
||||
return this.GetItemValueAsBoolean(ValueName, false);
|
||||
}
|
||||
|
||||
public bool GetItemValueAsBoolean(string ValueName, bool DefaultValue)
|
||||
{
|
||||
string val = this.GetItemValueAsString(ValueName);
|
||||
if ((((val.ToLower() == "1") || (val.ToLower() == "true")) || (val.ToLower() == "yes")) || (val.ToLower() == "on"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((((val.ToLower() == "0") || (val.ToLower() == "false")) || (val.ToLower() == "no")) || (val.ToLower() == "off"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return DefaultValue;
|
||||
}
|
||||
|
||||
public int GetItemValueAsInteger(string ValueName)
|
||||
{
|
||||
return this.GetItemValueAsInteger(ValueName, -1);
|
||||
}
|
||||
|
||||
public int GetItemValueAsInteger(string ValueName, int DefaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return int.Parse(this.GetItemValueAsString(ValueName, DefaultValue.ToString()));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetItemValueAsString(string ValueName)
|
||||
{
|
||||
return this.GetItemValueAsString(ValueName, "");
|
||||
}
|
||||
|
||||
public string GetItemValueAsString(string ValueName, string DefaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.GetItem(ValueName).Value.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public NameValuePairGroupCollection Groups
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarGroups;
|
||||
}
|
||||
}
|
||||
|
||||
public NameValuePair<T>.NameValuePairCollection Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarItems;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mvarName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string PathSeparator
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mvarPathSeparator;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mvarPathSeparator = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class NameValuePairGroupCollection : System.Collections.ObjectModel.Collection<NameValuePairGroup<T>>
|
||||
{
|
||||
public NameValuePairGroup<T> Add(string Name)
|
||||
{
|
||||
NameValuePairGroup<T> pg = new NameValuePairGroup<T>(Name);
|
||||
base.Add(pg);
|
||||
return pg;
|
||||
}
|
||||
|
||||
public bool Contains(string Name)
|
||||
{
|
||||
return (this[Name] != null);
|
||||
}
|
||||
|
||||
public bool Remove(string Name)
|
||||
{
|
||||
NameValuePairGroup<T> pg = this[Name];
|
||||
if (pg != null)
|
||||
{
|
||||
base.Remove(pg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public NameValuePairGroup<T> this[string Name]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (NameValuePairGroup<T> pg in this)
|
||||
{
|
||||
if (pg.Name == Name)
|
||||
{
|
||||
return pg;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,6 +74,8 @@
|
||||
<Compile Include="DataFormats\Text\Formatted\RichText\RTFGenerator.cs" />
|
||||
<Compile Include="DataFormats\UEPackage\UEPackageXMLDataFormat.cs" />
|
||||
<Compile Include="ExpandedString.cs" />
|
||||
<Compile Include="NameValuePair.cs" />
|
||||
<Compile Include="NameValuePairGroup.cs" />
|
||||
<Compile Include="ObjectModels\AbstractSyntax\AbstractSyntaxObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\Chunked\ChunkedObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\Chunked\RIFFChunk.cs" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user