<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:43:28 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-2759] Specify elements of SortDirection enum with appropriate values of MongoDB</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2759</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Now the elements of enum `SortDirection` does not have int numbers:&lt;/p&gt;

&lt;p&gt;```csharp&lt;/p&gt;

&lt;p&gt;public enum SortDirection&lt;/p&gt;
 {
&#160; &#160; Ascending,
&#160; &#160; Descending
 }

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Because of this, a lot of logic in the code of `MongoDB.Driver` library to verify compliance with the elements and numbers (-1 and 1) like this:&lt;/p&gt;

&lt;p&gt;```csharp&lt;/p&gt;

&lt;p&gt;switch (_direction)&lt;/p&gt;
 {
&#160; &#160; case SortDirection.Ascending:
&#160; &#160; &#160; &#160; value = 1;
&#160; &#160; &#160; &#160; break;
&#160; &#160; case SortDirection.Descending:
&#160; &#160; &#160; &#160; value = -1;
&#160; &#160; &#160; &#160; break;
 &#160; &#160; default:
&#160; &#160; &#160; &#160; throw new InvalidOperationException(&quot;Unknown value for &quot; + typeof(SortDirection) + &quot;.&quot;);
 }

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;This is unnecessary logic, because the C# has built-in casting enum to Int32 via setting numbers for appropriate enum elements. So the enum `SortDirection` might be refactored like this:&lt;/p&gt;

&lt;p&gt;```csharp&lt;/p&gt;

&lt;p&gt;public enum SortDirection&lt;/p&gt;
 {
&#160; &#160; Ascending = 1,
&#160; &#160; Descending = -1
 }

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;In this case no more additional logic needed. And in the future, if this numbers will be changed (for example, `100` for `Ascending` and `200` for `Descending`), there is one place to change code - `SortDirection` enum.&lt;/p&gt;

&lt;p&gt;Any string representation of `SortDirection` enum elements looks like this:&lt;/p&gt;

&lt;p&gt;```csharp&lt;/p&gt;

&lt;p&gt;$&quot;ascending is: {(int) SortDirection.Ascending}&quot;&lt;/p&gt;

&lt;p&gt;```&lt;/p&gt;</description>
                <environment></environment>
        <key id="942800">CSHARP-2759</key>
            <summary>Specify elements of SortDirection enum with appropriate values of MongoDB</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="12300">Won&apos;t Do</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="av-1991@yandex.ru">Valeriy Abakumov</reporter>
                        <labels>
                    </labels>
                <created>Fri, 27 Sep 2019 11:52:55 +0000</created>
                <updated>Mon, 30 Sep 2019 15:24:14 +0000</updated>
                            <resolved>Mon, 30 Sep 2019 15:24:14 +0000</resolved>
                                                                    <component>Feature Request</component>
                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="2440399" author="rstam" created="Mon, 30 Sep 2019 15:23:58 +0000"  >&lt;p&gt;It&apos;s an interesting suggestion, but I would summarize our thinking about it like this:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;The SortDirection enum represents the abstract concept of Ascending or Descending, independent of how that concept is represented in the query language&lt;/li&gt;
	&lt;li&gt;The abstract SortDirection is translated to 1 or -1 when translating abstract queries to actual queries&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Note also that a simple cast to int does &lt;b&gt;not&lt;/b&gt; check whether the value is valid. For that we&apos;d still need a switch statement anyway.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hvhhz3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>