Skip to content

Commit

Permalink
ICloneable - remove the shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCraver committed Feb 26, 2017
1 parent 8973afb commit 723d9d2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 63 deletions.
23 changes: 0 additions & 23 deletions src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs
Expand Up @@ -13,9 +13,6 @@ namespace StackExchange.Profiling.Data
/// </summary>
[System.ComponentModel.DesignerCategory("")]
public class ProfiledDbCommand : DbCommand
#if NET46
, ICloneable
#endif
{
private static Link<Type, Action<IDbCommand, bool>> bindByNameCache;
private DbCommand _command;
Expand Down Expand Up @@ -412,25 +409,5 @@ protected override void Dispose(bool disposing)
/// Gets the internal command.
/// </summary>
public DbCommand InternalCommand => _command;

#if NET46
/// <summary>
/// Clone this command, entity framework expects this behaviour.
/// </summary>
/// <returns>The <see cref="ProfiledDbCommand"/>.</returns>
/// <exception cref="NotSupportedException">Throws when te wrapped command is not <see cref="ICloneable"/>.</exception>
public ProfiledDbCommand Clone()
{ // EF expects ICloneable
var tail = _command as ICloneable;
if (tail == null) throw new NotSupportedException("Underlying " + _command.GetType().Name + " is not cloneable");
return new ProfiledDbCommand((DbCommand)tail.Clone(), _connection, _profiler);
}

/// <summary>
/// Creates a copy of this command.
/// </summary>
/// <returns>The <see cref="object"/>.</returns>
object ICloneable.Clone() => Clone();
#endif
}
}
21 changes: 0 additions & 21 deletions src/MiniProfiler.Shared/Data/ProfiledDbConnection.cs
Expand Up @@ -12,9 +12,6 @@ namespace StackExchange.Profiling.Data
/// </summary>
[System.ComponentModel.DesignerCategory("")]
public class ProfiledDbConnection : DbConnection
#if NET46
, ICloneable
#endif
{
private DbConnection _connection;
/// <summary>
Expand Down Expand Up @@ -185,24 +182,6 @@ private void StateChangeHandler(object sender, StateChangeEventArgs stateChangeE
/// <param name="restrictionValues">The restriction values.</param>
/// <returns>The <see cref="DataTable"/>.</returns>
public override DataTable GetSchema(string collectionName, string[] restrictionValues) => _connection.GetSchema(collectionName, restrictionValues);

/// <summary>
/// Creates a clone of this <see cref="ProfiledDbConnection"/>.
/// </summary>
/// <returns>The <see cref="ProfiledDbConnection"/>.</returns>
/// <exception cref="NotSupportedException">Throws when the connection is not <see cref="ICloneable"/></exception>
public ProfiledDbConnection Clone()
{
var tail = _connection as ICloneable;
if (tail == null) throw new NotSupportedException("Underlying " + _connection.GetType().Name + " is not cloneable");
return new ProfiledDbConnection((DbConnection)tail.Clone(), _profiler);
}

/// <summary>
/// Creates a clone of this <see cref="ProfiledDbConnection"/>.
/// </summary>
/// <returns>The <see cref="object"/>.</returns>
object ICloneable.Clone() => Clone();
#endif
}
}
19 changes: 0 additions & 19 deletions src/MiniProfiler.Shared/Data/SimpleProfiledCommand.cs
Expand Up @@ -9,9 +9,6 @@ namespace StackExchange.Profiling.Data
/// to collect profiling information.
/// </summary>
public class SimpleProfiledCommand : IDbCommand
#if NET46
, ICloneable
#endif
{
private IDbCommand _command;
private IDbConnection _connection;
Expand Down Expand Up @@ -207,21 +204,5 @@ protected virtual void Dispose(bool disposing)
_connection = null;
_profiler = null;
}

#if NET46
/// <summary>
/// Clones this command.
/// </summary>
/// <returns>The <see cref="object"/>.</returns>
/// <exception cref="NotSupportedException">Throw when the command is not <see cref="ICloneable"/>.</exception>
public object Clone()
{
var tail = _command as ICloneable;
if (tail == null)
throw new NotSupportedException("Underlying " + _command.GetType().Name + " is not cloneable.");

return new SimpleProfiledCommand((IDbCommand)tail.Clone(), _connection, _profiler);
}
#endif
}
}

0 comments on commit 723d9d2

Please sign in to comment.