Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Web.Entity.Design / System / Data / WebControls / Design / EntityDataSourceContainerNameConverter.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="EntityDataSourceContainerNameConverter.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       [....]
7 // @backupOwner [....]
8 //------------------------------------------------------------------------------
9
10 using System.Collections.Generic;
11 using System.ComponentModel;
12 using System.ComponentModel.Design;
13 using System.Diagnostics;
14 using System.Web.UI.WebControls;
15
16 namespace System.Web.UI.Design.WebControls
17 {    
18     internal class EntityDataSourceContainerNameConverter : StringConverter
19     {
20         
21         public EntityDataSourceContainerNameConverter()
22             : base()
23         {
24         }
25
26         public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
27         {
28             // We can only get a list of possible DefaultContainerName values if we have:
29             //    (1) Connection string so we can load metadata
30             // Even if this value is set, it may not be possible to actually load the metadata, but at least we can try the lookup if requested
31
32             EntityDataSource entityDataSource = context.Instance as EntityDataSource;
33             if (entityDataSource != null && !String.IsNullOrEmpty(entityDataSource.ConnectionString))
34             {
35                 List<EntityDataSourceContainerNameItem> containerNameItems = new EntityDataSourceDesignerHelper(entityDataSource, false /*interactiveMode*/).GetContainerNames(true /*sortResults*/);
36                 string[] containers = new string[containerNameItems.Count];
37                 for (int i = 0; i < containerNameItems.Count; i++)
38                 {
39                     containers[i] = containerNameItems[i].ToString();
40                 }
41                 return new StandardValuesCollection(containers);                
42             }
43
44             return null;
45         }
46
47         public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
48         {
49             return false;
50         }
51
52         public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
53         {
54             return true;
55         }
56     }
57 }