The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ClassMemberDisplayLayout Attribute Classs?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brendan Tompkins

Posts: 158
Nickname: brendant
Registered: Apr, 2005

Brendan Tompkins is .NET Developer and founder of CodeBetter.Com
ClassMemberDisplayLayout Attribute Classs? Posted: Apr 14, 2005 7:40 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Brendan Tompkins.
Original Post: ClassMemberDisplayLayout Attribute Classs?
Feed Title: Brendan Tompkins
Feed URL: /error.htm?aspxerrorpath=/blogs/brendan.tompkins/Rss.aspx
Feed Description: Blog First. Ask Questions Later.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Brendan Tompkins
Latest Posts From Brendan Tompkins

Advertisement

A few weeks ago, Raymond IM’d me and asked if I remembered the attribute that you can apply to your class to force the explicit layout of members.  I asked him why he would need or care about the layout of his class members, and he asked me: “Do you use NUnit?” and I immediately understood why he cared.

NUnit, in it’s GUI, presents your test cases in alphabetical oder, not in the order that you created them in your class. Other programs like Reflector also present the methods in alpha order, in fact it looks like members are laid out in IL in this order.   This can be a little confusing when you’re doing TDD, and you’ve written a bunch of test cases, and you go to implement them.  So say you have this test fixture:

  [TestFixture]

  public class LiveLinkServiceTest

  {

    LiveLinkPrincipal [] liveLinkUsers;

 

    [SetUp]

    public void SetUp()

    {

      LiveLinkConfigInfoProvider llcip = new  LiveLinkConfigInfoProvider();

      liveLinkUsers = llcip.GetAllLiveLinkUsers(); 

      Assert.IsNotNull(liveLinkUsers, "LiveLinkPrinipal Array is NULL");

      Assert.IsTrue(liveLinkUsers.Length > 0, "LiveLinkPrinipal Array is EMPTY");

    }

 

    [Test]

    public void TestGetLiveLinkTransactions()

    { 

      LiveLinkService lls = new LiveLinkService();

      ContainerTransactions cts = lls.GetNewTransactions(System.DateTime.Now.Subtract(TimeSpan.FromMinutes(10)),liveLinkUsers[0]);

      Assert.IsTrue(cts.CONTAINER_TRANSACTIONS.Count > 0, "Container Transactions is empty");

      Console.Out.WriteLine(cts.GetXml());

    }

 

    â€¦ // Rest of class removed

}

Here’s how it ends up looking in NUnit… Note that the order of my tests are alphabetical, not in the order I arranged them in my class.

Unittest1

NUnit will load the DLL, and display your methods in alphabetical order, unless it’s already loaded and cached the tests, in which case it adds new methods that it finds to the bottom of the tree.  This only happens when the DLL is re-loaded.

It’d be nice to test them one at a time, from top-to-bottom, as you write the code and go “green”, in the order that you arrange them in code.

So, here’s the point of this post.  Is there an attribute that you can use to order these methods inside an assembly?  I’ve researched StructLayout Attribute Class. and while it will affect your assembly class’ fields, methods are not affected.

If there’s not an existing attribute, would it make sense to have one that programs like Reflector and NUnit, that use reflection to determine class members, can use to determine method ordering for display purposes?

How about ClassMemberDisplayLayout Attribute Classs? Would this make sense?

-Brendan

Read: ClassMemberDisplayLayout Attribute Classs?

Topic: Of scary security practices Previous Topic   Next Topic Topic: Disk Space Exhaustion via Crystal Reports Vulnerability

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use