This is a multi-part message in MIME format.

------=_NextPart_000_0029_01C8E9F2.0D2C65B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,
Is it possible to make the C# compiler to keep the order of Custom =
attributes as it is in the source file?

For example, I've got the following output from the code snippet below: =
4, 3, 1, 2
Can I preserve the original order at the moment of compilation?


[Test(1)]

[Test(2)]

[Test(3)]

[Test(4)]

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

=20

foreach (TestAttribute a in =
GetType().GetCustomAttributes(typeof(TestAttribute), true))

MessageBox.Show(a.Ordinal.ToString());

}

}

=20

[AttributeUsage(AttributeTargets.Class, AllowMultiple=3Dtrue)]

public class TestAttribute : Attribute

{

private readonly int _ordinal;

=20

public TestAttribute(int ordinal)

{

_ordinal =3D ordinal;

}

=20

public int Ordinal=20

{

get { return _ordinal; }

}

}



Thanks,

-- dmitry



------=_NextPart_000_0029_01C8E9F2.0D2C65B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6001.18063" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Is it possible to make the C# compiler =
to keep the=20
order of Custom attributes as it is in the source file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>For example, I've got the following =
output from the=20
code snippet below: 4, 3, 1, 2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Can I preserve the original order at =
the moment of=20
compilation?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(1)]<?xml:namespace prefix =3D o ns =
=3D=20
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(2)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(3)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(4)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">partial</SPAN> <SPAN=20
style=3D"COLOR: blue">class</SPAN> <SPAN style=3D"COLOR: =
#2b91af">Form1</SPAN> :=20
<SPAN style=3D"COLOR: #2b91af">Form<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> =
Form1()<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>InitializeComponent();<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">foreach</SPAN> (<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN> a <SPAN=20
style=3D"COLOR: blue">in</SPAN> GetType().GetCustomAttributes(<SPAN=20
style=3D"COLOR: blue">typeof</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN>), <SPAN=20
style=3D"COLOR: blue">true</SPAN>))<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN=20
style=3D"COLOR: =
#2b91af">MessageBox</SPAN>.Show(a.Ordinal.ToString());<o:p></o:p></SPAN><=
/P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">AttributeUsage</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">AttributeTargets</SPAN>.Class, =
AllowMultiple=3D<SPAN=20
style=3D"COLOR: blue">true</SPAN>)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">class</SPAN> <SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Attribute<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">private</SPAN> <SPAN=20
style=3D"COLOR: blue">readonly</SPAN> <SPAN style=3D"COLOR: =
blue">int</SPAN>=20
_ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> TestAttribute(<SPAN=20
style=3D"COLOR: blue">int</SPAN> ordinal)<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>_ordinal =3D ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> <SPAN=20
style=3D"COLOR: blue">int</SPAN> Ordinal <o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">get</SPAN> { <SPAN=20
style=3D"COLOR: blue">return</SPAN> _ordinal; }<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-bidi-language: =
HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes">Thanks,</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes">--=20
dmitry</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: =
yes"></SPAN>&nbsp;</P></FONT></DIV></BODY></HTML>

------=_NextPart_000_0029_01C8E9F2.0D2C65B0--

Re: Keeping the order of custom attributes by Nicholas

Nicholas
Sat Jul 19 22:28:56 CDT 2008

This is a multi-part message in MIME format.

------=_NextPart_000_002D_01C8E9F7.367DD7F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dmitry,

No, it isn't. However, if you are using LINQ, you can do so by =
exposing a property through the attrbitute which exposes the 1, 2, 3, 4, =
and then ordering on that property.


--=20
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dmitry Nogin" <dmitry.nogin@hotmail.com> wrote in message =
news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com...
Hi,
Is it possible to make the C# compiler to keep the order of Custom =
attributes as it is in the source file?

For example, I've got the following output from the code snippet =
below: 4, 3, 1, 2
Can I preserve the original order at the moment of compilation?


[Test(1)]

[Test(2)]

[Test(3)]

[Test(4)]

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

=20

foreach (TestAttribute a in =
GetType().GetCustomAttributes(typeof(TestAttribute), true))

MessageBox.Show(a.Ordinal.ToString());

}

}

=20

[AttributeUsage(AttributeTargets.Class, AllowMultiple=3Dtrue)]

public class TestAttribute : Attribute

{

private readonly int _ordinal;

=20

public TestAttribute(int ordinal)

{

_ordinal =3D ordinal;

}

=20

public int Ordinal=20

{

get { return _ordinal; }

}

}



Thanks,

-- dmitry



------=_NextPart_000_002D_01C8E9F7.367DD7F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6001.18063" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dmitry,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; No, it isn't.&nbsp; =
However, if=20
you are using LINQ, you can do so by exposing a property through the =
attrbitute=20
which exposes the 1, 2, 3, 4, and then ordering on that =
property.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR>--=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- Nicholas Paldino [.NET/C#=20
MVP]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- <A=20
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Dmitry Nogin" &lt;<A=20
=
href=3D"mailto:dmitry.nogin@hotmail.com">dmitry.nogin@hotmail.com</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com">news:C8A=
856F5-D61B-484E-918C-F12A77265B60@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Is it possible to make the C# =
compiler to keep=20
the order of Custom attributes as it is in the source =
file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>For example, I've got the following =
output from=20
the code snippet below: 4, 3, 1, 2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Can I preserve the original order at =
the moment=20
of compilation?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(1)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(2)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(3)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(4)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">partial</SPAN>=20
<SPAN style=3D"COLOR: blue">class</SPAN> <SPAN=20
style=3D"COLOR: #2b91af">Form1</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Form<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> =
Form1()<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>InitializeComponent();<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">foreach</SPAN> (<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN> a <SPAN=20
style=3D"COLOR: blue">in</SPAN> GetType().GetCustomAttributes(<SPAN=20
style=3D"COLOR: blue">typeof</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN>), <SPAN=20
style=3D"COLOR: blue">true</SPAN>))<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN=20
style=3D"COLOR: =
#2b91af">MessageBox</SPAN>.Show(a.Ordinal.ToString());<o:p></o:p></SPAN><=
/P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">AttributeUsage</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">AttributeTargets</SPAN>.Class, =
AllowMultiple=3D<SPAN=20
style=3D"COLOR: blue">true</SPAN>)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">class</SPAN> <SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Attribute<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN><SPAN style=3D"COLOR: blue">private</SPAN> <SPAN=20
style=3D"COLOR: blue">readonly</SPAN> <SPAN style=3D"COLOR: =
blue">int</SPAN>=20
_ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> TestAttribute(<SPAN=20
style=3D"COLOR: blue">int</SPAN> ordinal)<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>_ordinal =3D ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> <SPAN=20
style=3D"COLOR: blue">int</SPAN> Ordinal <o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">get</SPAN> { <SPAN=20
style=3D"COLOR: blue">return</SPAN> _ordinal; }<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes">Thanks,</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes">--=20
dmitry</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: =
yes"></SPAN>&nbsp;</P></FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_002D_01C8E9F7.367DD7F0--


Re: Keeping the order of custom attributes by Dmitry

Dmitry
Sun Jul 20 10:51:56 CDT 2008

This is a multi-part message in MIME format.

------=_NextPart_000_00CD_01C8EA5F.060717E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear Nicholas,
Thank you a lot.

Do I have any chances to generate these ordinals automatically? Or =
validate its order at runtime while debug build is executed?
It looks like StackFrame.GetFileLineNumber method will not help here...


-- dmitry

"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> =
wrote in message =
news:96B435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com...
Dmitry,

No, it isn't. However, if you are using LINQ, you can do so by =
exposing a property through the attrbitute which exposes the 1, 2, 3, 4, =
and then ordering on that property.


--=20
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dmitry Nogin" <dmitry.nogin@hotmail.com> wrote in message =
news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com...
Hi,
Is it possible to make the C# compiler to keep the order of Custom =
attributes as it is in the source file?

For example, I've got the following output from the code snippet =
below: 4, 3, 1, 2
Can I preserve the original order at the moment of compilation?


[Test(1)]

[Test(2)]

[Test(3)]

[Test(4)]

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

=20

foreach (TestAttribute a in =
GetType().GetCustomAttributes(typeof(TestAttribute), true))

MessageBox.Show(a.Ordinal.ToString());

}

}

=20

[AttributeUsage(AttributeTargets.Class, AllowMultiple=3Dtrue)]

public class TestAttribute : Attribute

{

private readonly int _ordinal;

=20

public TestAttribute(int ordinal)

{

_ordinal =3D ordinal;

}

=20

public int Ordinal=20

{

get { return _ordinal; }

}

}



Thanks,

-- dmitry



------=_NextPart_000_00CD_01C8EA5F.060717E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6001.18063" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear Nicholas,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thank you a lot.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Do I have&nbsp;any chances to generate =
these=20
ordinals automatically? Or validate its order&nbsp;at runtime&nbsp;while =
debug=20
build is executed?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It looks like =
StackFrame.GetFileLineNumber method=20
will not help here...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-- dmitry</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Nicholas Paldino [.NET/C# MVP]" &lt;<A=20
=
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:96B435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com">news:96B=
435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Dmitry,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; No, it =
isn't.&nbsp; However,=20
if you are using LINQ, you can do so by exposing a property through =
the=20
attrbitute which exposes the 1, 2, 3, 4, and then ordering on that=20
property.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR>--=20
=
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- Nicholas Paldino [.NET/C#=20
=
MVP]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- <A=20
=
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Dmitry Nogin" &lt;<A=20
=
href=3D"mailto:dmitry.nogin@hotmail.com">dmitry.nogin@hotmail.com</A>&gt;=
=20
wrote in message <A=20
=
href=3D"news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com">news:C8A=
856F5-D61B-484E-918C-F12A77265B60@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Is it possible to make the C# =
compiler to keep=20
the order of Custom attributes as it is in the source =
file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>For example, I've got the following =
output from=20
the code snippet below: 4, 3, 1, 2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Can I preserve the original order =
at the moment=20
of compilation?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(1)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(2)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(3)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(4)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">partial</SPAN>=20
<SPAN style=3D"COLOR: blue">class</SPAN> <SPAN=20
style=3D"COLOR: #2b91af">Form1</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Form<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> =
Form1()<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>InitializeComponent();<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">foreach</SPAN> (<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN> a <SPAN=20
style=3D"COLOR: blue">in</SPAN> GetType().GetCustomAttributes(<SPAN=20
style=3D"COLOR: blue">typeof</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">TestAttribute</SPAN>), <SPAN=20
style=3D"COLOR: blue">true</SPAN>))<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN=20
style=3D"COLOR: =
#2b91af">MessageBox</SPAN>.Show(a.Ordinal.ToString());<o:p></o:p></SPAN><=
/P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">AttributeUsage</SPAN>(<SPAN=20
style=3D"COLOR: #2b91af">AttributeTargets</SPAN>.Class, =
AllowMultiple=3D<SPAN=20
style=3D"COLOR: blue">true</SPAN>)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">class</SPAN>=20
<SPAN style=3D"COLOR: #2b91af">TestAttribute</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Attribute<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; =
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">private</SPAN> <SPAN=20
style=3D"COLOR: blue">readonly</SPAN> <SPAN style=3D"COLOR: =
blue">int</SPAN>=20
_ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> TestAttribute(<SPAN =

style=3D"COLOR: blue">int</SPAN> ordinal)<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>_ordinal =3D ordinal;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">public</SPAN> <SPAN=20
style=3D"COLOR: blue">int</SPAN> Ordinal <o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">get</SPAN> { <SPAN=20
style=3D"COLOR: blue">return</SPAN> _ordinal; =
}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: =
yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes">Thanks,</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: yes">--=20
dmitry</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 10pt"><SPAN=20
style=3D"FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier =
New'; mso-bidi-language: HE; mso-no-proof: =
yes"></SPAN>&nbsp;</P></FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTM=
L>

------=_NextPart_000_00CD_01C8EA5F.060717E0--


Re: Keeping the order of custom attributes by Nicholas

Nicholas
Sun Jul 20 19:54:05 CDT 2008

This is a multi-part message in MIME format.

------=_NextPart_000_002F_01C8EAAA.BF8714E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dmitry,

You could generate the ordinals at runtime, but they would be =
generated in the order they are created, not in the manner you are =
expecting, so that's not really an option.

What exactly are you trying to do?


--=20
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dmitry Nogin" <dmitry.nogin@hotmail.com> wrote in message =
news:E868EA76-654C-4FC4-95B5-E0022E139671@microsoft.com...
Dear Nicholas,
Thank you a lot.

Do I have any chances to generate these ordinals automatically? Or =
validate its order at runtime while debug build is executed?
It looks like StackFrame.GetFileLineNumber method will not help =
here...


-- dmitry

"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> =
wrote in message =
news:96B435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com...
Dmitry,

No, it isn't. However, if you are using LINQ, you can do so by =
exposing a property through the attrbitute which exposes the 1, 2, 3, 4, =
and then ordering on that property.


--=20
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dmitry Nogin" <dmitry.nogin@hotmail.com> wrote in message =
news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com...
Hi,
Is it possible to make the C# compiler to keep the order of Custom =
attributes as it is in the source file?

For example, I've got the following output from the code snippet =
below: 4, 3, 1, 2
Can I preserve the original order at the moment of compilation?


[Test(1)]

[Test(2)]

[Test(3)]

[Test(4)]

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

=20

foreach (TestAttribute a in =
GetType().GetCustomAttributes(typeof(TestAttribute), true))

MessageBox.Show(a.Ordinal.ToString());

}

}

=20

[AttributeUsage(AttributeTargets.Class, AllowMultiple=3Dtrue)]

public class TestAttribute : Attribute

{

private readonly int _ordinal;

=20

public TestAttribute(int ordinal)

{

_ordinal =3D ordinal;

}

=20

public int Ordinal=20

{

get { return _ordinal; }

}

}



Thanks,

-- dmitry



------=_NextPart_000_002F_01C8EAAA.BF8714E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6001.18063" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dmitry,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; You could generate =
the ordinals=20
at runtime, but they would be generated in the order they are created, =
not in=20
the manner you are expecting, so that's not really an =
option.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; What exactly are you =
trying to=20
do?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR>--=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- Nicholas Paldino [.NET/C#=20
MVP]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- <A=20
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Dmitry Nogin" &lt;<A=20
=
href=3D"mailto:dmitry.nogin@hotmail.com">dmitry.nogin@hotmail.com</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:E868EA76-654C-4FC4-95B5-E0022E139671@microsoft.com">news:E86=
8EA76-654C-4FC4-95B5-E0022E139671@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Dear Nicholas,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thank you a lot.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Do I have&nbsp;any chances to =
generate these=20
ordinals automatically? Or validate its order&nbsp;at =
runtime&nbsp;while debug=20
build is executed?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It looks like =
StackFrame.GetFileLineNumber method=20
will not help here...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-- dmitry</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Nicholas Paldino [.NET/C# MVP]" &lt;<A=20
=
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:96B435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com">news:96B=
435C6-69DC-44BD-819E-682C1AA079BF@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Dmitry,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; No, it =
isn't.&nbsp; However,=20
if you are using LINQ, you can do so by exposing a property through =
the=20
attrbitute which exposes the 1, 2, 3, 4, and then ordering on that=20
property.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR>--=20
=
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- Nicholas Paldino [.NET/C#=20
=
MVP]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
- <A=20
=
href=3D"mailto:mvp@spam.guard.caspershouse.com">mvp@spam.guard.caspershou=
se.com</A></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Dmitry Nogin" &lt;<A=20
=
href=3D"mailto:dmitry.nogin@hotmail.com">dmitry.nogin@hotmail.com</A>&gt;=
=20
wrote in message <A=20
=
href=3D"news:C8A856F5-D61B-484E-918C-F12A77265B60@microsoft.com">news:C8A=
856F5-D61B-484E-918C-F12A77265B60@microsoft.com</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Is it possible to make the C# =
compiler to=20
keep the order of Custom attributes as it is in the source=20
file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>For example, I've got the =
following output=20
from the code snippet below: 4, 3, 1, 2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Can I preserve the original order =
at the=20
moment of compilation?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(1)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(2)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(3)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN=20
style=3D"COLOR: #2b91af">Test</SPAN>(4)]<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20
style=3D"mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN=20
style=3D"COLOR: blue">public</SPAN> <SPAN style=3D"COLOR: =
blue">partial</SPAN>=20
<SPAN style=3D"COLOR: blue">class</SPAN> <SPAN=20
style=3D"COLOR: #2b91af">Form1</SPAN> : <SPAN=20
style=3D"COLOR: #2b91af">Form<o:p></o:p></SPAN></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; =
mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; =
mso-bidi-language: HE; mso-no-proof: yes"><SPAN=20