PC Review


Reply
Thread Tools Rate Thread

Comment order

 
 
puzzlecracker
Guest
Posts: n/a
 
      17th Oct 2008
what goes first: the comment or attribute:

/// This is a Foo class
[Serializable]
public abstract class Foo: INetSerializable
{


}

Or

[Serializable]
/// This is a Foo class
public abstract class Foo: INetSerializable
{


}

Thanks
 
Reply With Quote
 
 
 
 
Michael B. Trausch
Guest
Posts: n/a
 
      17th Oct 2008
On Fri, 17 Oct 2008 12:04:57 -0700 (PDT)
puzzlecracker <(E-Mail Removed)> wrote:
> what goes first: the comment or attribute:
>
> /// This is a Foo class
> [Serializable]
> public abstract class Foo: INetSerializable {}
>
> Or
>
> [Serializable]
> /// This is a Foo class
> public abstract class Foo: INetSerializable {}
>


A quick experiment will show if it makes any difference at all. First
things first, attributes can be have an explicitly specified target, or
their target can be implied by their location in the source code.
Certain targets, such as the assembly, must always be explicitly
specified.

Now, let's make a sample program showing both forms:

===== BEGIN CODE
using System;

public class Entry {
public static void Main() {
decimal a = 2;
decimal b = 3;

Console.WriteLine("{0} / {1} = {2}", a, b, a/b);
ShowResult0(a, b);
ShowResult1(a, b);
}

// form 1
[Obsolete("Don't use this method, use ShowResult1 instead")]
public static void ShowResult0(decimal a, decimal b) {
Console.WriteLine("{0} / {1} = {2}", a, b, a/b);
}

[Obsolete("Don't use this method, use ShowResult0 instead")]
// form 2
public static void ShowResult1(decimal a, decimal b) {
Console.WriteLine("{0} / {1} = {2}", a, b, a/b);
}
}
===== END CODE

Okay, now let's compile it:
Friday, 2008-Oct-17 at 15:13:17 - mbt@zest - Linux v2.6.27
Ubuntu Intrepid:[1-18/6198-0]:test> gmcs decimal.cs 2>&1 |fold -s -w 72
decimal.cs(9,5): warning CS0618: `Entry.ShowResult0(decimal, decimal)'
is obsolete: `Don't use this method, use ShowResult1 instead'
decimal.cs(10,5): warning CS0618: `Entry.ShowResult1(decimal, decimal)'
is obsolete: `Don't use this method, use ShowResult0 instead'
Compilation succeeded - 2 warning(s)

We see that the compiler picked up both. If you compile the code and
then take a look at the IL, you'll see that the attribute is recognized
and placed in both methods.

For clarity, I would do the comment first, and the attribute next, and
the method third. But, that is a matter of preference. The C#
compiler does not care, as long as it can apply the attribute to the
next thing in the source code.

HTH,
Mike

--
My sigfile ran away and is on hiatus.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREDAAYFAkj45GQACgkQ0kE/IBnFmjCz0QCdG14Gbd7js0v9ChRC0XJcS1Zk
Tp8An1GsI4KX81LcROWUY9n16cSmIwKW
=rpoY
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Ralf Jansen
Guest
Posts: n/a
 
      17th Oct 2008
puzzlecracker schrieb:
> what goes first: the comment or attribute:
>
> /// This is a Foo class
> [Serializable]
> public abstract class Foo: INetSerializable
> {
>
>
> }
>
> Or
>
> [Serializable]
> /// This is a Foo class
> public abstract class Foo: INetSerializable
> {
>
>
> }
>
> Thanks


I use first.
Having an Attribute just before an XML Comment (the triple slash ones)
like your second example has will prevent automatic folding on that Comment(at
least in my VS2008).

Other then that it should make no difference.

--
Ralf Jansen

deepinvent Software GmbH - Viersen, Germany - http://www.deepinvent.com
Central Email Archiving The Easy Way - http://www.mailstore.com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Excel comment on mouseover but not the comment indicator jrfauteux@gmail.com Microsoft Excel Programming 5 29th Sep 2010 11:59 PM
Edit Comment erases part of screen; comment uneditable Charles Blaquière Microsoft Excel Discussion 0 10th Sep 2008 08:31 PM
Mouse-over on comment highlights barely shows comment text GordonM Microsoft Word Document Management 0 9th Apr 2008 01:13 AM
a comment plugin & copy paste directly from excel to comment ? fr. =?Utf-8?B?UkZN?= Microsoft Excel Worksheet Functions 0 1st Dec 2004 11:29 PM
Re: after updating or entering a comment, the date is entered into that comment John Vinson Microsoft Access 0 4th Jun 2004 01:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:37 PM.