Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Web.Entity.Design / System / Data / WebControls / Design / EntityDataSourceContainerNameItem.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="EntityDataSourceContainerNameItem.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       [....]
7 // @backupOwner [....]
8 //------------------------------------------------------------------------------
9
10 using System.Data.Metadata.Edm;
11 using System.Diagnostics;
12
13 namespace System.Web.UI.Design.WebControls
14 {
15     internal class EntityDataSourceContainerNameItem : IComparable<EntityDataSourceContainerNameItem>
16     {
17         // Only one of the following should be set. This is enforced through the constructors and the fact that these fields are readonly.
18         private readonly EntityContainer _entityContainer; // used when we have a real EntityContainer backing this item
19         private readonly string _unknownContainerName; // used when we have an unknown DefaultContainerName that we still want to include in the list
20         
21         internal EntityDataSourceContainerNameItem(EntityContainer entityContainer)
22         {
23             Debug.Assert(entityContainer != null, "null entityContainer");
24             _entityContainer = entityContainer;            
25         }
26
27         internal EntityDataSourceContainerNameItem(string unknownContainerName)
28         {
29             Debug.Assert(!String.IsNullOrEmpty(unknownContainerName), "null or empty unknownContainerName");
30             _unknownContainerName = unknownContainerName;
31         }
32
33         internal string EntityContainerName
34         {
35             get
36             {
37                 if (_entityContainer != null)
38                 {
39                     return _entityContainer.Name;
40                 }
41                 else
42                 {
43                     return _unknownContainerName;
44                 }
45             }
46         }
47
48         internal EntityContainer EntityContainer
49         {
50             get
51             {
52                 // may be null if this represents an unknown container
53                 return _entityContainer;
54             }
55         }
56
57         public override string ToString()
58         {
59             return this.EntityContainerName;
60         }
61         
62         int IComparable<EntityDataSourceContainerNameItem>.CompareTo(EntityDataSourceContainerNameItem other)
63         {
64             return (String.Compare(this.EntityContainerName, other.EntityContainerName, StringComparison.OrdinalIgnoreCase));
65         }
66     }
67 }