Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / EntityClient / EntityProviderFactory.cs
1 //---------------------------------------------------------------------
2 // <copyright file="EntityProviderFactory.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  [....]
7 // @backupOwner [....]
8 //---------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Diagnostics.CodeAnalysis;
11 using System.Text;
12 using System.Data;
13 using System.Data.Common;
14 using System.Security;
15 using System.Security.Permissions;
16
17 namespace System.Data.EntityClient
18 {
19     /// <summary>
20     /// Class representing a provider factory for the entity client provider
21     /// </summary>
22     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2302", Justification="We don't expect serviceType to be an Embedded Interop Types.")]
23     public sealed class EntityProviderFactory : DbProviderFactory, IServiceProvider
24     {
25         /// <summary>
26         /// A singleton object for the entity client provider factory object
27         /// </summary>
28         [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EntityProviderFactory implements the singleton pattern and it's stateless.  This is needed in order to work with DbProviderFactories.")]
29         public static readonly EntityProviderFactory Instance = new EntityProviderFactory();
30
31         /// <summary>
32         /// Constructs the EntityProviderFactory object, this is private as users shouldn't create it directly
33         /// </summary>
34         private EntityProviderFactory()
35         {
36         }
37
38         /// <summary>
39         /// Creates a EntityCommand object and returns it
40         /// </summary>
41         /// <returns>A EntityCommand object</returns>
42         public override DbCommand CreateCommand()
43         {
44             return new EntityCommand();
45         }
46
47         /// <summary>
48         /// Creates a EntityCommandBuilder object and returns it
49         /// </summary>
50         /// <returns>A EntityCommandBuilder object</returns>
51         /// <exception cref="NotSupportedException"></exception>
52         public override DbCommandBuilder CreateCommandBuilder()
53         {
54             throw EntityUtil.NotSupported();
55         }
56
57         /// <summary>
58         /// Creates a EntityConnection object and returns it
59         /// </summary>
60         /// <returns>A EntityConnection object</returns>
61         public override DbConnection CreateConnection()
62         {
63             return new EntityConnection();
64         }
65
66         /// <summary>
67         /// Creates a EntityConnectionStringBuilder object and returns it
68         /// </summary>
69         /// <returns>A EntityConnectionStringBuilder object</returns>
70         public override DbConnectionStringBuilder CreateConnectionStringBuilder()
71         {
72             return new EntityConnectionStringBuilder();
73         }
74
75         /// <summary>
76         /// Creates a DbDataAdapter object and returns it, this method is currently not supported
77         /// </summary>
78         /// <returns>A DbDataAdapter object</returns>
79         /// <exception cref="NotSupportedException"></exception>
80         public override DbDataAdapter CreateDataAdapter()
81         {
82             throw EntityUtil.NotSupported();
83         }
84
85         /// <summary>
86         /// Creates a EntityParameter object and returns it
87         /// </summary>
88         /// <returns>A EntityParameter object</returns>
89         public override DbParameter CreateParameter()
90         {
91             return new EntityParameter();
92         }
93
94         /// <summary>
95         /// Creates a CodeAccessPermission object and returns it
96         /// </summary>
97         /// <param name="state">The permission state level for the code access</param>
98         /// <returns>A CodeAccessPermission object</returns>
99         public override CodeAccessPermission CreatePermission(PermissionState state)
100         {
101             throw EntityUtil.NotSupported();
102         }
103
104         /// <summary>
105         /// Extension mechanism for additional services;  
106         /// </summary>
107         /// <returns>requested service provider or null.</returns>
108         object IServiceProvider.GetService(Type serviceType) {
109             object result = null;
110             if (serviceType == typeof(DbProviderServices)) {
111                 result = EntityProviderServices.Instance;
112             }
113             else if (serviceType == typeof(IEntityAdapter)) {
114                 result = new EntityAdapter();
115             }
116             return result;
117         }    
118     }
119 }