2004-05-22 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
[mono.git] / mcs / class / Npgsql / Npgsql / Design / NpgsqlParametersEditor.cs
1 using System;
2 using System.ComponentModel.Design;
3
4 namespace Npgsql.Design
5 {
6         /// <summary>
7         /// Zusammenfassung fr NpgsqlParametersEditor.
8         /// </summary>
9         internal class NpgsqlParametersEditor : CollectionEditor
10         {
11                 NpgsqlParameterCollection parameters;
12                 public NpgsqlParametersEditor(Type type) : base(type){
13                         this.parameters = null;
14                 }
15         
16                 protected override bool CanSelectMultipleInstances() {
17                         return false;
18                 }
19         
20                 protected override object CreateInstance(Type itemType) {
21                         NpgsqlParameter param = base.CreateInstance(itemType) as NpgsqlParameter;
22                         if (param != null){
23                                 param.ParameterName = this.GetUniqueParameterName(this.parameters, ":Parameter", 1);
24                         }
25                         return param;
26                 }
27         
28                 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) {
29                         this.parameters = value as NpgsqlParameterCollection;
30                         return base.EditValue (context, provider, value);
31                 }
32         
33                 protected override string HelpTopic {
34                         get {
35                                         return "vs.data.collectioneditor.parameter";
36                         }
37                 }
38                 private string GetUniqueParameterName(NpgsqlParameterCollection parameters, string Prefix, int InitialPostfix){
39                         int Postfix = InitialPostfix;
40                         string ReturnValue = String.Empty;
41                         bool IsInside = true;
42                         while(IsInside){
43                                 ReturnValue = String.Concat(Prefix, Postfix.ToString());
44                                 if(parameters == null)
45                                         break;
46                                 IsInside = parameters.Contains(ReturnValue);
47                                 Postfix++;
48                         }
49                         return ReturnValue;
50                 }
51         }
52 }