Hi,
You can use these extension methods.
/// <summary>
/// Gets the value of a custom property.
/// </summary>
/// <param name="db">Database the method applys to.</param>
/// <param name="key">Property key.</param>
/// <returns>The property value or null if not found.</returns>
public static string GetCustomProperty(this Database db, string key)
{
DatabaseSummaryInfoBuilder sumInfo = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
IDictionary custProps = sumInfo.CustomPropertyTable;
return ((string)custProps[key]).Trim();
}
/// <summary>
/// Gets the Database properties.
/// </summary>
/// <param name="db">Database the method applys to.</param>
/// <returns>A dictionary containing the custom properties.</returns>
public static Dictionary<string, string> GetCustomProperties(this Database db)
{
Dictionary<string, string> result = new Dictionary<string, string>();
IDictionaryEnumerator dictEnum = db.SummaryInfo.CustomProperties;
while (dictEnum.MoveNext())
{
DictionaryEntry entry = dictEnum.Entry;
result.Add((string)entry.Key, ((string)entry.Value).Trim());
}
return result;
}
/// <summary>
/// Sets the value of an existing property or create it if it didn't exist.
/// </summary>
/// <param name="db">Database the method applys to.</param>
/// <param name="key">Property key.</param>
/// <param name="value">Property value.</param>
public static void SetCustomProperty(this Database db, string key, string value)
{
DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
IDictionary custProps = infoBuilder.CustomPropertyTable;
if (custProps.Contains(key))
custProps[key] = value;
else
custProps.Add(key, value);
db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
}
/// <summary>
/// Sets the values of existing properties or create those which didn't exist.
/// </summary>
/// <param name="db">Database the method applys to.</param>
/// <param name="values">Key/Value pairs for the properties.</param>
public static void SetCustomProperties(this Database db, params KeyValuePair<string, string>[] values)
{
DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
IDictionary custProps = infoBuilder.CustomPropertyTable;
foreach (KeyValuePair<string, string> pair in values)
{
string key = pair.Key;
if (custProps.Contains(key))
custProps[key] = pair.Value;
else
custProps.Add(key, pair.Value);
}
db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
}