Thursday, 29 March 2012

Saturday, 17 March 2012

Navigating code without Resharper

 

Use Ctrl+K, Ctrl+V for class view search, then type the member name you want to go to...

image

Although on large solutions it's not quite as blistering fast as Resharper navigation

You can also invoke static methods from here to test them, without having to spin up MSTest or the like...

image

Friday, 16 March 2012

Visual Studio Slow when connecting to test results (.trx)

Just found this worked for me, when connecting to test runs...

http://blogs.msdn.com/b/lkruger/archive/2008/06/03/slow-performance-in-visual-studio-2008-ide-after-opening-test-project.aspx

Disable background discovery of test methods: (Available in VS2008 SP1 only)

1. Select the Tools | Options | Test Tools | Test Project menu option.

2. On the Test Project dialog (figure 1.1), select the “Disable background discover of test methods” checkbox option and press ok.

This will disable the background discovery of test methods and will dramatically speed up the IDE. However, since this is global option, this will disable the test method discovery on every project. If you wish to re-enable the discovery, simply load the Test Project dialog again and deselect the “Disable background discover of test methods” checkbox.

 

Also, another tip is to set the option "Double-clicking a failed or inconclusive unit test result displays the point of failure in the test"

image

Thursday, 15 March 2012

Resharper TODO Explorer Custom Tags

 

Today I stumbled across a very neat little feature in Resharper that can help immensely when carrying out large code refactoring on a solution as we're doing now currently in our code base. (http://www.jetbrains.com/resharper/webhelp/Configuring_ReSharper__Sharing_Configuration_Options.html )

Turns out you can set up custom tags for the TODO item explorer, and use these to jump quickly through the code base to locations that you need to come back to at a later date (using Ctrl+Alt+PgDown when the TODO item explorer is the active window)

We've created a custom tag of DBR to easily search for code areas relating to database refactor tasks that need doing still. ..

clip_image001

This then automatically gets added to anyone working on our branch via saving off the custom tag into the team MySolution.sln.DotSettings file, which is then added to source control as a Solution Item…

clip_image002

Then, with the TODO item explorer (Ctrl+Alt+D) you can filter for these tags only in code as follows…

clip_image003

If you have any custom tags you wish to add to the team shared folder then you'll need to copy them to the team shared file (ensure you have it checked out first), via the Resharper, Manage Options, menu option as follows…

clip_image004 clip_image005

You can type whilst the TODO explorer window is activated, and it will filter to those items that have the search phrase you typed in…

image

More information here about all of this...

http://www.jetbrains.com/resharper/webhelp/Configuring_ReSharper__Sharing_Configuration_Options.html

Friday, 9 March 2012

Decompiling sources with JetBrains Resharper 6.x

http://blogs.jetbrains.com/dotnet/2011/02/resharper-6-bundles-decompiler-free-standalone-tool-to-follow/

Just class this. Tried it today on System.String and compared the output to .NET Reflector version.

image

Thing is the JetBrains one comes out as a file that is fully Navigable (if that's even a word!) using Resharper itself. Superb!

Tuesday, 6 March 2012

How to Speed up the Visual Studio IDE

Here's my list. All of these can be accessed on Tools->Options menu:
  1. Disable F1. (Environment->Keyboard) This is probably the best advice that I found somewhere.
  2. Disable "Animate environment tools" (Environment->General).
  3. Disable Start Page (Environment->Startup).
  4. Disable "Track Active Item in Solution Explorer" (Projects and Solutions).
  5. Disable Navigation Bar (Text Editor->C#). I think this is available for every language.
  6. Set "AutoToolboxPopulate" to false (Windows Forms Designer).
  7. You can set the Code view as the default view when viewing Windows Forms. Just right-click on the cs file and select "Open With...".
  8. Open Visual Studio using the command line (devenv) rather than using the Start menu. I don't know why but I notice it loads faster.
  9. Turn off Track Changes. (Text Editor->Track changes)
Also have a look at this post for more tricks you can do

Monday, 5 March 2012

Visual Studio 11 Ultimate Beta - First look

More about it here http://blogs.msdn.com/b/jasonz/archive/2012/02/29/welcome-to-the-beta-of-visual-studio-11-and-net-framework-4-5.aspx

 

Appears as if they're trying to put Resharper out of business to me, with the new call hierarchy window.

Also you can navigate direct to methods from solution explorer.

image

The default colour scheme for the Dark theme, from tool, options setting, is a black coding window. With the light scheme, the coding window returns back to the default colours that most use out of the box with older versions of VS.

New generate dependency graph for solution option under the Architecture. Great idea in theory, in practice it takes ages to complete, even for a small one method console application. Could be useful though if you have a large project that you're getting to grips with, only if you have the time to run it though.

image

Appears that Code review support, is very integral in the new VS 11 IDE as well.

image

Friday, 2 March 2012

Listing Windows Services from a command prompt

For a simple list of windows services you can run the following command from a command prompt...

> net start

(also net stop "my service name" will stop the service)

However for more detailed information on the services on your machine, you can run the %windir%\system32\sc.exe. Due to the amount of detailed output that comes out as well, it's probably worth piping this through a more command as follows...

> sc query | more

Problem with reseeding IDENTITY column in a SQL Server 2008 database table

Problem that we've just discovered with DBCC CHECKIDENT ('MyTable', reseed, 1) which doesn't reset the identity seed to 1 if the table has had data in it before, instead the newly inserted rows will start from ID = 2.

Example below…

begin tran

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MerrickTest]') AND type in (N'U'))

DROP TABLE [dbo].[MerrickTest]

CREATE TABLE [dbo].[MerrickTest](

            [ID] [int] IDENTITY(1,1) NOT NULL,

            [Value] [varchar](50) NULL,

CONSTRAINT [PK_MerrickTest] PRIMARY KEY CLUSTERED

(

            [ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

SELECT IDENT_SEED('dbo.MerrickTest') AS Identity_Seed;

insert into merricktest (value) values ( 'test' )

select * from merricktest

delete from MerrickTest

SELECT IDENT_SEED('dbo.MerrickTest') AS Identity_Seed;

DBCC CHECKIDENT (merricktest, reseed, 1)

SELECT IDENT_SEED('dbo.MerrickTest') AS Identity_Seed;

insert into merricktest (value) values ( 'test' )

select * from merricktest -- note that the value in the ID column is now 2 not 1

drop table MerrickTest

rollback

image

Solution...

One solution you could use for this is to check the last update on the database table, and then reseed from zero if it has been updated in the past using the following sql

Select object_name(object_id), last_user_update from sys.dm_db_index_usage_stats where object_name(object_id) like 'MerrickTest'

image

Thursday, 1 March 2012

Accessing properties in C# using Lambda Expression Trees

The following code example shows how to reference properties on classes using Lambda expressions, rather than having to rely on a myType.GetType().GetProperties().First(prop => prop.Name == "MyPropertyName") type search, which would not be as easy to refactor in the future.

Here's a method that'll return the PropertyInfo object for the expression. It throws an exception if the expression is not a property.

public PropertyInfo GetPropertyInfo<TSource, TProperty>(
    TSource source,
    Expression<Func<TSource, TProperty>> propertyLambda)
{
    Type type = typeof(TSource);

    MemberExpression member = propertyLambda.Body as MemberExpression;
    if (member == null)
        throw new ArgumentException(string.Format(
            "Expression '{0}' refers to a method, not a property.",
            propertyLambda.ToString()));

    PropertyInfo propInfo = member.Member as PropertyInfo;
    if (propInfo == null)
        throw new ArgumentException(string.Format(
            "Expression '{0}' refers to a field, not a property.",
            propertyLambda.ToString()));

    if (type != propInfo.ReflectedType &&
        !type.IsSubclassOf(propInfo.ReflectedType))
        throw new ArgumentException(string.Format(
            "Expresion '{0}' refers to a property that is not from type {1}.",
            propertyLambda.ToString(),
            type));

    return propInfo;
}

Usage as follows ...

var propertyInfo = GetPropertyInfo(someUserObject, u => u.UserID);
 

More info here


http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...