2 using System
.ComponentModel
;
3 using System
.ComponentModel
.Design
.Serialization
;
5 using System
.Reflection
;
7 namespace Npgsql
.Design
10 /// Zusammenfassung fr NpgsqlParameterConverter.
12 internal class NpgsqlParameterConverter
: ExpandableObjectConverter
14 public NpgsqlParameterConverter()
17 // TODO: Fgen Sie hier die Konstruktorlogik hinzu
21 public override bool CanConvertTo(ITypeDescriptorContext context
, Type destinationType
) {
22 if (destinationType
== typeof(InstanceDescriptor
))
24 return base.CanConvertTo (context
, destinationType
);
27 public override object ConvertTo(ITypeDescriptorContext context
, System
.Globalization
.CultureInfo culture
, object value, Type destinationType
) {
28 if(destinationType
== null){
29 throw new ArgumentNullException("destinationType");
31 if(destinationType
== typeof(InstanceDescriptor
) && value as NpgsqlParameter
!= null){
32 NpgsqlParameter param
= (NpgsqlParameter
)value;
33 bool DbTypeChanged
= false;
34 bool OtherChanged
= false;
35 bool SizeChanged
= false;
36 bool SourceColumnChanged
= false;
37 bool ValueChanged
= false;
38 if(param
.DbType
!= DbType
.String
){
41 if(param
.Direction
!= ParameterDirection
.Input
|| param
.Precision
!= 0 || param
.Scale
!= 0 || param
.SourceVersion
!= DataRowVersion
.Current
|| param
.IsNullable
== true){
47 if(param
.SourceColumn
== null || param
.SourceColumn
.Trim() != String
.Empty
){
48 SourceColumnChanged
= true;
50 if(param
.Value
!= null){
54 if(!(OtherChanged
|| SizeChanged
|| SourceColumnChanged
|| ValueChanged
)){
55 ConstructorInfo ci
= typeof(NpgsqlParameter
).GetConstructor(new Type
[]{typeof(String), typeof(DbType)}
);
57 return new InstanceDescriptor(ci
, new Object
[]{param.ParameterName, param.DbType}
);
59 }else if(!(OtherChanged
|| SourceColumnChanged
|| ValueChanged
)){
60 ConstructorInfo ci
= typeof(NpgsqlParameter
).GetConstructor(new Type
[]{typeof(String), typeof(DbType), typeof(Int32)}
);
62 return new InstanceDescriptor(ci
, new Object
[]{param.ParameterName, param.DbType, param.Size}
);
64 }else if(!(OtherChanged
|| ValueChanged
)){
65 ConstructorInfo ci
= typeof(NpgsqlParameter
).GetConstructor(new Type
[]{typeof(String), typeof(DbType), typeof(Int32), typeof(String)}
);
67 return new InstanceDescriptor(ci
, new Object
[]{param.ParameterName, param.DbType, param.Size, param.SourceColumn}
);
69 }else if(ValueChanged
&& !DbTypeChanged
){
70 ConstructorInfo ci
= typeof(NpgsqlParameter
).GetConstructor(new Type
[]{typeof(String), typeof(Object)}
);
72 return new InstanceDescriptor(ci
, new Object
[]{param.ParameterName, param.Value}
);
75 ConstructorInfo ci
= typeof(NpgsqlParameter
).GetConstructor(new Type
[]{typeof(String), typeof(DbType), typeof(Int32), typeof(String), typeof(ParameterDirection), typeof(Boolean), typeof(Byte), typeof(Byte), typeof(DataRowVersion), typeof(Object)}
);
77 return new InstanceDescriptor(ci
, new Object
[]{param.ParameterName, param.DbType, param.Size, param.SourceColumn, param.Direction, param.IsNullable, param.Precision, param.Scale, param.SourceVersion, param.Value}
);
81 return base.ConvertTo (context
, culture
, value, destinationType
);