csharp Vitosha的Resharper模板

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Vitosha的Resharper模板相关的知识,希望对你有一定的参考价值。

/// <summary>
/// Selects a collection of <see cref="$InfoType$" /> from the database
/// </summary>
/// <param name="$entityId$">$Param1Description$</param>
/// <returns>Data transfer object for the <see cref="$InfoType$" /></returns>
public $CollectionType$<$InfoType$> Get$Name$($parameterType$ $entityId$)
{
	return Get$Name$($entityId$, null);
}


/// <summary>
/// Selects a collection of <see cref="$InfoType$" /> from the database
/// </summary>
/// <param name="$entityId$">$Param1Description$</param>
/// <param name="transaction">Database transaction</param>
/// <returns>Collection of a Data transfer objects</returns>
internal $CollectionType$<$InfoType$> Get$Name$($parameterType$ $entityId$, DbTransaction transaction)
{
	Database database;
	DbCommand command;
	IDataReader reader = null;

	try
	{
		object[] parameters = new object[1];

		parameters[0] = $entityId$;

		database = DatabaseFactory.CreateDatabase();
		command = database.GetStoredProcCommand("[dbo].[$ProcedureName$]", parameters);
		reader = database.ExecuteReader(command);
		
		if (transaction != null)
		{
			reader = database.ExecuteReader(command, transaction);
		}
		else
		{
			reader = database.ExecuteReader(command);
		}

		$CollectionType$<$InfoType$> result = new $CollectionType$<$InfoType$>();
		$InfoType$ info;


		while (reader.Read())
		{
			info = new $InfoType$();
			
			$FillMethod$(info, reader);

			result.Add(info);
		}

		return result;
	}
	finally
	{
		if (reader != null)
		{
			reader.Dispose();
		}
	}
}
/// <summary>
/// Selects a <see cref="$InfoType$" /> from the database
/// </summary>
/// <param name="$entityId$">Identifier of the <see cref="$InfoType$" /></param>
/// <returns>Data transfer object for the <see cref="$InfoType$" /></returns>
public $InfoType$ Get$Name$($parameterType$ $entityId$)
{
	Database database;
	DbCommand command;
	IDataReader reader = null;

	try
	{
		object[] parameters = new object[1];

		parameters[0] = $entityId$;

		database = DatabaseFactory.CreateDatabase();
		command = database.GetStoredProcCommand("[dbo].[$ProcedureName$]", parameters);
		reader = database.ExecuteReader(command);

		$InfoType$ info = null;

		if (reader.Read())
		{
			info = new $InfoType$();
			
			$FillMethod$(info, reader);
		}

		return info;
	}
	finally
	{
		if (reader != null)
		{
			reader.Dispose();
		}
	}
}
public bool $methodName$Delete(int $entityId$)
{
	return $methodName$Delete($entityId$, null);
}

internal bool $methodName$Delete(int $entityId$, DbTransaction transaction)
{
	Database database;
	DbCommand command = null;

	try
	{
		var parameters = new object[1];
        parameters[0] = $entityId$;

        database = DatabaseFactory.CreateDatabase();
        command = database.GetStoredProcCommand("[dbo].[$procedureName$]", parameters);

        int result = (int)(transaction != null
                    ? database.ExecuteScalar(command, transaction)
                    : database.ExecuteScalar(command));

        return result == 1;
	}
	finally
    {
        if (command != null)
        {
            command.Dispose();
        }
    }
}
/// <summary>
/// Inserts a $Name$ in the database
/// </summary>
/// <param name="$infoName$">Data transfer object for $Name$</param>
/// <returns>Data transfer object for the $Name$ with identifier</returns>
public $InfoType$ Create$Name$($InfoType$ $infoName$)
{
	return Create$Name$($infoName$, null);
}

/// <summary>
/// Inserts a $Name$ in the database
/// </summary>
/// <param name="$infoName$">Data transfer object for $Name$</param>
/// <param name="transaction">Database transaction</param>
/// <returns>Data transfer object for the $Name$ with identifier</returns>
internal $InfoType$ Create$Name$($InfoType$ $infoName$, DbTransaction transaction)
{
	Database database;
	DbCommand command = null;

	try
	{
		object[] parameters = new object[$ParametersCount$];

		parameters[0] = 

		database = DatabaseFactory.CreateDatabase();
		command = database.GetStoredProcCommand("[dbo].[$ProcedureName$]", parameters);

		if (transaction != null)
		{
			$infoName$.Id = Convert.ToInt32(database.ExecuteScalar(command, transaction), CultureInfo.InvariantCulture);
		}
		else
		{
			$infoName$.Id = Convert.ToInt32(database.ExecuteScalar(command), CultureInfo.InvariantCulture);
		}

		return $infoName$;
	}
	finally
	{
		if (command != null)
		{
			command.Dispose();
		}
	}
}
/// <summary>
/// Updates a $Name$ in the database
/// </summary>
/// <param name="$infoName$">Data transfer object for $Name$</param>
/// <returns><code>true</code> if the operation was successful</returns>
public bool Update$Name$($InfoType$ $infoName$)
{
	return Update$Name$($infoName$, null);
}

/// <summary>
/// Updates a $Name$ in the database
/// </summary>
/// <param name="$infoName$">Data transfer object for $Name$</param>
/// <param name="transaction">Database transaction</param>
/// <returns><code>true</code> if the operation was successful</returns>
internal bool Update$Name$($InfoType$ $infoName$, DbTransaction transaction)
{
	Database database;
	DbCommand command = null;

	try
	{
		object[] parameters = new object[$ParametersCount$];

		parameters[0] = $infoName$.;

		database = DatabaseFactory.CreateDatabase();
		command = database.GetStoredProcCommand("[dbo].[$ProcedureName$]", parameters);
		int result;

		if (transaction != null)
		{
			result = Convert.ToInt32(database.ExecuteScalar(command, transaction), CultureInfo.InvariantCulture);
		}
		else
		{
			result = Convert.ToInt32(database.ExecuteScalar(command), CultureInfo.InvariantCulture);
		}

		return result == 1;
	}
	finally
	{
		if (command != null)
		{
			command.Dispose();
		}
	}
}

以上是关于csharp Vitosha的Resharper模板的主要内容,如果未能解决你的问题,请参考以下文章

C++ 的 ReSharper [关闭]

ReSharper 配置及用法(ZHUANG)

Resharper:vars

Resharper:vars

ReSharper 8.2.1 不工作

resharper 8.1