/// <summary> /// Gets the value from the property set that has the given <paramref name="name" />. /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="source">The property set.</param> /// <param name="name">The name.</param> /// <param name="defaultValue">The default value.</param> /// <returns> /// Returns the value for the property with the specified name; otherwise the <paramref name="defaultValue" /> will be /// returned. /// </returns> public static TValue GetProperty <TValue>(this IPropertySet source, string name, TValue defaultValue) { if (source != null) { foreach (var entry in source.AsEnumerable()) { if (string.Equals(name, entry.Key, StringComparison.CurrentCultureIgnoreCase)) { return(TypeCast.Cast(entry.Value, defaultValue)); } } } return(defaultValue); }
/// <summary> /// Gets the workspace factory used by the connection properties. /// </summary> /// <param name="connectionProperties">The connection properties.</param> /// <returns> /// Returns a <see cref="IWorkspaceFactory" /> representing the workspace for the connection properties; otherwise /// <c>null</c> /// </returns> public static IWorkspaceFactory GetFactory(IPropertySet connectionProperties) { var list = connectionProperties.AsEnumerable() .ToDictionary(o => o.Key, o => o.Value.ToString()); string server; list.TryGetValue("SERVER", out server); string instance; list.TryGetValue("INSTANCE", out instance); string database; list.TryGetValue("DATABASE", out database); string version; list.TryGetValue("VERSION", out version); DBMS type = GetDBMS(server, instance, database, version); switch (type) { case DBMS.Access: return(new AccessWorkspaceFactoryClass()); case DBMS.Oracle: case DBMS.SqlServer: return(new SdeWorkspaceFactoryClass()); case DBMS.File: return(new FileGDBWorkspaceFactoryClass()); } throw new NotSupportedException("The workspace factory cannot be determined from the connection properties."); }
public void IPropertySet_AsEnumerable_Count_Equals_3() { Assert.AreEqual(3, _PropertySet.AsEnumerable().Count()); }