File: EntityConnectionStringBuilderItem.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (108 lines) | stat: -rw-r--r-- 3,840 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//------------------------------------------------------------------------------
// <copyright file="EntityConnectionStringBuilderItem.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       [....]
// @backupOwner [....]
//------------------------------------------------------------------------------

using System.Data.EntityClient;
using System.Diagnostics;

namespace System.Web.UI.Design.WebControls
{
    internal class EntityConnectionStringBuilderItem : IComparable<EntityConnectionStringBuilderItem>
    {
        // Only one of the following should be set. This is enforced through the constructors and the fact that these fields are readonly.
        private readonly EntityConnectionStringBuilder _connectionStringBuilder;
        private readonly string _unknownConnectionString; // used when the string cannot be loaded into a connection string builder or is missing some required keywords

        internal EntityConnectionStringBuilderItem(EntityConnectionStringBuilder connectionStringBuilder)
        {
            // empty connection string builder is allowed, but not null
            Debug.Assert(connectionStringBuilder != null, "null connectionStringBuilder");

            _connectionStringBuilder = connectionStringBuilder;
        }

        internal EntityConnectionStringBuilderItem(string unknownConnectionString)
        {
            // empty is not allowed -- use the constructor that takes a builder if the string is empty
            Debug.Assert(!String.IsNullOrEmpty(unknownConnectionString), "null or empty unknownConnectionString");
            _unknownConnectionString = unknownConnectionString;
        }

        internal string ConnectionString
        {
            get
            {
                if (_connectionStringBuilder != null)
                {
                    return _connectionStringBuilder.ConnectionString;
                }
                else
                {
                    return _unknownConnectionString;
                }
            }
        }

        internal EntityConnectionStringBuilder EntityConnectionStringBuilder
        {
            get
            {
                return _connectionStringBuilder;
            }
        }

        internal bool IsEmpty
        {
            get
            {
                return String.IsNullOrEmpty(this.ConnectionString);
            }
        }

        internal bool IsNamedConnection
        {
            get
            {
                if (_connectionStringBuilder != null)
                {
                    return !String.IsNullOrEmpty(_connectionStringBuilder.Name);
                }
                else
                {
                    // if the connection string is not recognized by a EntityConnectionStringBuilder, it can't be a valid named connection
                    return false;
                }
            }
        }
        
        public override string ToString()
        {
            // Display just the name for named connections, but the full connection string otherwise
            if (_connectionStringBuilder != null)
            {
                if (!String.IsNullOrEmpty(_connectionStringBuilder.Name))
                {
                    return _connectionStringBuilder.Name;
                }
                else
                {
                    return _connectionStringBuilder.ConnectionString;
                }
            }
            else
            {
                return _unknownConnectionString;
            }
        }

        int IComparable<EntityConnectionStringBuilderItem>.CompareTo(EntityConnectionStringBuilderItem other)
        {
            return (String.Compare(this.ToString(), other.ToString(), StringComparison.OrdinalIgnoreCase));
        }
    }
}