C# File Layout Problem with DependencyProperty Fields

I am having a problem with the file layout feature of R# in C# files in which dependency properties are not caught within any defined region. I would like to define a region to surround only dependency properties, but even the "Default with regions" pattern leaves all of my dependency properites at the bottom of my C# files, even below the catch all "All Other Members" region.

I wonder if others have seen this behavior, and if anyone knows how to make this work.

I think I have the latest production version of R# installed.

JetBrains ReSharper Platform 6 Build 6.0.20141219.120158 on 2014-12-19 12:56:02Z
JetBrains dotCover 3.0 Update 1 Build 3.0.20141219.140120 on 2014-12-19 14:04:16Z
JetBrains dotMemory 4.2 Update 1 Build 4.2.20141219.130159 on 2014-12-19 13:21:38Z
JetBrains dotTrace 6.0 Update 1 Build 6.0.20141219.130145 on 2014-12-19 13:21:24Z
JetBrains ReSharper 9.0 Update 1 Build 9.0.20141219.130142 on 2014-12-19 13:12:31Z

Gil

4 comments
Comment actions Permalink

I have experimented a bit with this to see what I could find on my own. One thing that seems to have some bearing is I found that for the root "Patterns" node I had the StaticFieldReorderingPolicy attribute set to "Strict." (I think that is the default value.) When I set the attribute to "Relaxed," Most of the dependency properties were placed in the fields region. Two though still ended up at the end of the file outside of any region.

The only difference between those that were placed within the fields region and those that were not is that the latter specified one of the Register properties with a defined "const" string whereas all of the other dependency properties had regular strings using double quote characters.

If I set StaticFieldReorderingPolicy to "Unrestricted," all of the dependency properties are placed within the fields region.

I can see that the purpose of setting a reordering policy for static fields is to prevent errors that would result runtime errors if the fields were dependent on previous changes, but I don't think there are any depdencies like that in the code that I am writing. So is the purpose of this behavior "just in case" such a dependency exists? If the strict setting requires that static properites be placed at the end of the file without reordering the properties, is there a way still to have those properties be placed within a region, either using the GUI FileLayout tool, or editing the XAML?

I would appreciate your suggestions.

0
Comment actions Permalink

Hello Gil,

  There is the following feature in YouTrack https://youtrack.jetbrains.com/issue/RSRP-429318. According to the comment left by the developer, there will be some changes in sorting/grouping DependencyProperty elements in ReSharper 9.1. If you have additional suggestions, you are welcome to comment such feature request.

Thanks!

0
Comment actions Permalink

Hello,

If it's a "const", then the restriction is probably by mistake because there's
no link to the literals (consts) at runtime.

As for static fields getting to the end of the file, that's because R# won't
touch them if it sees it dangerous (e.g. fields are referencing each other
and changing their order might cause nullrefs at runtime). They're not actually
moved to the end, but all other members are picked and inserted in the beginning
of the class in their proper order, so what's left untouched ends up at the
bottom.

We've discussed the matter and there're two supposed improvements which might
be implemented in newer versions:
(1) Better detection of the fields which are dangerous to move around, and
which are known to be OK.
(2) Partial order on the fields, i.e. the fields are not moved against one
another but laid out at the proper part of the file.
I don't know of any time frame for that.

Pity C# has it such a mess around static fields referencing one another.


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

If it's a "const", then the restriction is probably by mistake because there's
no link to the literals (consts) at runtime.

This seems to be the case under the "Relaxed" mode, but the problem is only a minor problem, because when the mode is "Unrestricted" all of the fields, static or otherwise go into the expected regions.

I rarely reference other fields within static contexts (at least not purposefully), so the unrestricted mode seems to work for me.

Thanks.

Gil

0

Please sign in to leave a comment.