#if MYSQL_6_10 // Copyright ?2004, 2018, Oracle and/or its affiliates. All rights reserved. // // MySQL Connector/NET is licensed under the terms of the GPLv2 // , like most // MySQL Connectors. There are special exceptions to the terms and // conditions of the GPLv2 as it is applied to this software, see the // FLOSS License Exception // . // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published // by the Free Software Foundation; version 2 of the License. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; using System.Data.Common; using System.Reflection; #if !NETSTANDARD1_3 using System.Security.Permissions; #endif namespace Externals.MySql.Data.MySqlClient { /// /// Represents a set of methods for creating instances of the MySQL client implementation of the data source classes. /// #if !NETSTANDARD1_3 [ReflectionPermission(SecurityAction.Assert, MemberAccess = true)] #endif internal sealed partial class MySqlClientFactory : DbProviderFactory, IServiceProvider { /// /// Gets an instance of the . /// This can be used to retrieve strongly typed data objects. /// public static MySqlClientFactory Instance = new MySqlClientFactory(); private Type _dbServicesType; private FieldInfo _mySqlDbProviderServicesInstance; /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbCommand. public override DbCommand CreateCommand() { return new MySqlCommand(); } /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbConnection. public override DbConnection CreateConnection() { return new MySqlConnection(); } /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbParameter. public override DbParameter CreateParameter() { return new MySqlParameter(); } /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbConnectionStringBuilder. public override DbConnectionStringBuilder CreateConnectionStringBuilder() { return new MySqlConnectionStringBuilder(); } #if !NETSTANDARD1_3 /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbCommandBuilder. public override DbCommandBuilder CreateCommandBuilder() { return new MySqlCommandBuilder(); } /// /// Returns a strongly typed instance. /// /// A new strongly typed instance of DbDataAdapter. public override DbDataAdapter CreateDataAdapter() { return new MySqlDataAdapter(); } #endif #region IServiceProvider Members /// /// Provide a simple caching layer /// private Type DbServicesType => _dbServicesType ?? (_dbServicesType = Type.GetType( @"System.Data.Common.DbProviderServices, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", false)); private FieldInfo MySqlDbProviderServicesInstance { get { if (_mySqlDbProviderServicesInstance == null) { #if NETSTANDARD1_3 string fullName = typeof(MySqlClientFactory).GetTypeInfo().Assembly.FullName; #else string fullName = Assembly.GetExecutingAssembly().FullName; #endif string assemblyName = fullName.Replace("Externals.MySql.Data", "Externals.MySql.Data.Entity.EF6"); string assemblyEf5Name = fullName.Replace("Externals.MySql.Data", "Externals.MySql.Data.Entity.EF5"); fullName = $"Externals.MySql.Data.MySqlClient.MySqlProviderServices, {assemblyEf5Name}"; Type providerServicesType = Type.GetType(fullName, false); if (providerServicesType == null) { fullName = $"Externals.MySql.Data.MySqlClient.MySqlProviderServices, {assemblyName}"; providerServicesType = Type.GetType(fullName, false); if (providerServicesType == null) throw new DllNotFoundException(fullName); } _mySqlDbProviderServicesInstance = providerServicesType.GetField("Instance", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); } return _mySqlDbProviderServicesInstance; } } object IServiceProvider.GetService(Type serviceType) { // DbProviderServices is the only service we offer up right now return serviceType != DbServicesType ? null : MySqlDbProviderServicesInstance?.GetValue(null); } #endregion } } #endif