Member reordering and LayoutKind.Sequential

Is it possible to modify the "Reformat Code" command so it will ignore the structs which have "StructLayout(LayoutKind.Sequential)" set. Even if "Reorder type members" is checked on reformat.

Those errors are very hard to find especially when they happen after "simple" reformat...

10 comments
Comment actions Permalink

They are not touched!

Please could you visit ReSharper options, and in "Type Member Layout" page
check the layout (one of the first rules tells ReSharper to not to touch
such structs). If the "default" checkbox is checked, then uncheck it to see
he default pattern

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"alex" <no_reply@jetbrains.com> wrote in message
news:23693186.1202223828404.JavaMail.itn@is.intellij.net...

Is it possible to modify the "Reformat Code" command so it will ignore the
structs which have "StructLayout(LayoutKind.Sequential)" set. Even if
"Reorder type members" is checked on reformat.

>

Those errors are very hard to find especially when they happen after
"simple" reformat...



0
Comment actions Permalink

I am using the default template (the checkbox was unchecked) and it has nothing about sequential layout. Is that the old version? Attaching the template

When reformatting this structure:

public struct NetResourceData
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;

public string lpLocalName;

public string lpRemoteName;

public string lpComment;

public string lpProvider;

} ;
changes to this:

public struct NetResourceData
{
public int dwDisplayType;
public int dwScope;
public int dwType;
public int dwUsage;


public string lpComment;


public string lpLocalName;


public string lpProvider;


public string lpRemoteName;
} ;
Very annoying...



Attachment(s):
default template.txt
0
Comment actions Permalink

The default pattern is fixed in ReSharper 4.0.

To modify the pattern at your side, please replace the very first rule by
the following:

-- Eugene Pasynkov Developer JetBrains, Inc http://www.jetbrains.com "Develop with pleasure!" "alex" wrote in message news:2790355.1202225922893.JavaMail.itn@is.intellij.net... >I am using the default template (the checkbox was unchecked) and it has >nothing about sequential layout. Is that the old version? Attaching the >template >]]>

When reformatting this structure:

public struct NetResourceData
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;

public string lpLocalName;

public string lpRemoteName;

public string lpComment;

public string lpProvider;

>

} ;
changes to this:

public struct NetResourceData
{
public int dwDisplayType;
public int dwScope;
public int dwType;
public int dwUsage;

>


public string lpComment;

>


public string lpLocalName;

>


public string lpProvider;

>


public string lpRemoteName;
} ;
Very annoying...



0
Comment actions Permalink

That's not enough. It needs to also ignore classes with the StructLayout attribute set. Classes can be used in place of structs for P/Invoke when the passed as ref parameters.

Please update the template to ignore both structs and classes with the attribute.

Thanks,
--Oren

0
Comment actions Permalink

Yes, this fixes the probem for the structs.
Thank you!

0
Comment actions Permalink

As far as I know, the StructLayout attribute is not applicable for classes

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Oren Novotny" <no_reply@jetbrains.com> wrote in message
news:4111760.1202236704281.JavaMail.itn@is.intellij.net...

That's not enough. It needs to also ignore classes with the StructLayout
attribute set. Classes can be used in place of structs for P/Invoke when
the passed as ref parameters.

>

Please update the template to ignore both structs and classes with the
attribute.

>

Thanks,
--Oren



0
Comment actions Permalink

It is and does work. Please check the source code to the BCL via reflector. You'll see that Microsoft themselves use classes in place of some structs.

This is desireable and useful for structures where there's a struct size parameter as you can easily use Marshal.SizeOf(this) in the ctor.

If the P/Invoke signature was


void Blah(int param, ref SomeStruct param2);

You could do void Blah(int param, SomeClass param2) instead and it'll work.

As a more concrete example, please check the Microsoft.Win32.Win32Native+OSVERSIONINFO class in mscorlib with reflector. You'll see that there are several places where they use classes instead of structs for p/invoke calls.

Also, the docs at
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx

Specify the attribute target can be either a class or struct.

I'd think that overall, it'd be easier for you guys to make your code just look for the attribute and not bother knowing if it's a class/struct. Let the compiler figure that out based on attribute target usage...

Thanks!

Message was edited by:
Oren Novotny

0
Comment actions Permalink

Any update on my request?

Thanks!

0
Comment actions Permalink

I'll modify the default pattern in ReSharper 4.0

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Oren Novotny" <no_reply@jetbrains.com> wrote in message
news:17058289.1202824687682.JavaMail.itn@is.intellij.net...

Any update on my request?

>

Thanks!



0

Please sign in to leave a comment.