コード例 #1
0
        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() });
        }
コード例 #2
0
        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); }
        }
コード例 #3
0
		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() };
		}
コード例 #4
0
		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; }
		}