public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { var list = value as IEnumerable <EditDatabaseConnectDialog.DBParam>; var type = list.Select(dbParam => dbParam.DBType).FirstOrDefault(); var builder = new DBConnectInfo { Type = type }.GetBuilder(); var props = builder.GetType().GetProperties().ToDictionary(prop => prop.Name); list.Where(dbParam => !dbParam.IsDefault).ForEach(dbParam => props[dbParam.Name].SetValue(builder, System.Convert.ChangeType(dbParam.Value, props[dbParam.Name].PropertyType))); return(new object[] { type, builder.ToString() }); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if ((values[0] == null) || (values[1] == null) || (!(values[0] is DBConnectInfo.DBType)) || ((DBConnectInfo.DBType)values[0] == DBConnectInfo.DBType.None) || (!(values[1] is string))) { return(DependencyProperty.UnsetValue); } var dbType = (DBConnectInfo.DBType)values[0]; var connStr = values[1] as string; try { var builder = new DBConnectInfo { Type = dbType, ConnectionString = connStr }.GetBuilder(); var defaults = new DBConnectInfo { Type = dbType }.GetBuilder(); var baseProps = new HashSet <string>(typeof(DbConnectionStringBuilder).GetProperties().Select(prop => prop.Name)); var props = builder.GetType().GetProperties().Where(prop => !baseProps.Contains(prop.Name)).Where(prop => prop.CanWrite).Where(prop => prop.GetIndexParameters().Length == 0).ToList(); return(props.Select(prop => new EditDatabaseConnectDialog.DBParam(dbType, prop, builder, defaults)).OrderBy(dbParam => dbParam.IsDefault).ToList()); } catch { return(DependencyProperty.UnsetValue); } }
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { var list = value as IEnumerable<EditDatabaseConnectDialog.DBParam>; var type = list.Select(dbParam => dbParam.DBType).FirstOrDefault(); var builder = new DBConnectInfo { Type = type }.GetBuilder(); var props = builder.GetType().GetProperties().ToDictionary(prop => prop.Name); list.Where(dbParam => !dbParam.IsDefault).ForEach(dbParam => props[dbParam.Name].SetValue(builder, System.Convert.ChangeType(dbParam.Value, props[dbParam.Name].PropertyType))); return new object[] { type, builder.ToString() }; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if ((values[0] == null) || (values[1] == null) || (!(values[0] is DBConnectInfo.DBType)) || ((DBConnectInfo.DBType)values[0] == DBConnectInfo.DBType.None) || (!(values[1] is string))) return DependencyProperty.UnsetValue; var dbType = (DBConnectInfo.DBType)values[0]; var connStr = values[1] as string; try { var builder = new DBConnectInfo { Type = dbType, ConnectionString = connStr }.GetBuilder(); var defaults = new DBConnectInfo { Type = dbType }.GetBuilder(); var baseProps = new HashSet<string>(typeof(DbConnectionStringBuilder).GetProperties().Select(prop => prop.Name)); var props = builder.GetType().GetProperties().Where(prop => !baseProps.Contains(prop.Name)).Where(prop => prop.CanWrite).Where(prop => prop.GetIndexParameters().Length == 0).ToList(); return props.Select(prop => new EditDatabaseConnectDialog.DBParam(dbType, prop, builder, defaults)).OrderBy(dbParam => dbParam.IsDefault).ToList(); } catch { return DependencyProperty.UnsetValue; } }