<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Takaaki Suzuki on Medium]]></title>
        <description><![CDATA[Stories by Takaaki Suzuki on Medium]]></description>
        <link>https://medium.com/@xin9le?source=rss-1a98c6c5d9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*o5FlqCjFBSZY96jF-fL8Sw.jpeg</url>
            <title>Stories by Takaaki Suzuki on Medium</title>
            <link>https://medium.com/@xin9le?source=rss-1a98c6c5d9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:14:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xin9le/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[FastEnum : The world fastest enum utility for C#/.NET]]></title>
            <link>https://medium.com/@xin9le/fastenum-the-world-fastest-enum-utility-for-c-net-a616b9b2c901?source=rss-1a98c6c5d9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a616b9b2c901</guid>
            <category><![CDATA[high-performance]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[netstandard]]></category>
            <category><![CDATA[enum]]></category>
            <dc:creator><![CDATA[Takaaki Suzuki]]></dc:creator>
            <pubDate>Mon, 16 Sep 2019 11:17:01 GMT</pubDate>
            <atom:updated>2019-09-17T03:19:22.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>FastEnum : The world fastest enum utility for C#/.NET</h3><p>I have released <a href="https://github.com/xin9le/FastEnum"><strong>FastEnum</strong></a> that is the world <strong><em>FASTEST</em></strong> enum utility for C#/.NET. It’s much faster than .NET Core, and also faster than <a href="https://github.com/TylerBrinkley/Enums.NET">Enums.NET</a> that is similar library. Provided methods are all achieved zero allocation.</p><p><a href="https://github.com/xin9le/FastEnum">GitHub - xin9le/FastEnum: The world fastest enum utilities for C#/.NET</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/0*48SjFO1_jWvW8dt8.png" /></figure><p>This library is quite useful to significantly improve your performance because enum is really popular feature.</p><h3>How to use</h3><p>This library super easy to use like System.Enum that is standard of .NET. Look below:</p><pre>//--- FastEnum<br>var values = FastEnum.GetValues&lt;Fruits&gt;();<br>var names = FastEnum.GetNames&lt;Fruits&gt;();<br>var name = FastEnum.GetName&lt;Fruits&gt;(Fruits.Apple);<br>var name = Fruits.Apple.ToName();<br>var defined = FastEnum.IsDefined&lt;Fruits&gt;(123);<br>var parse = FastEnum.Parse&lt;Fruits&gt;(&quot;Apple&quot;);<br>var tryParse = FastEnum.TryParse&lt;Fruits&gt;(&quot;Apple&quot;, out var value);</pre><pre>//--- .NET<br>var values = Enum.GetValues(typeof(Fruits)) as Fruits[];<br>var names = Enum.GetNames(typeof(Fruits));<br>var name = Enum.GetName(typeof(Fruits), Fruits.Apple);<br>var name = Fruits.Apple.ToString();<br>var defined = Enum.IsDefined(typeof(Fruits), 123);<br>var parse = Enum.Parse&lt;Fruits&gt;(&quot;Apple&quot;);<br>var tryParse = Enum.TryParse&lt;Fruits&gt;(&quot;Apple&quot;, out var value);</pre><p>As you can see, the replacement from System.Enum is very easy. You never confuse.</p><h3>More features</h3><p>There are some functions that are often used for enum, and you can be used more conveniently by including them together.</p><h4>1. Gets pairwised member information</h4><p>Sometimes you want value / name pair of enum. Member&lt;TEnum&gt; can be used under such cases. FieldInfo is also included, so please use it for reflection code.</p><pre>class Member&lt;TEnum&gt;<br>{<br>    public TEnum Value { get; }<br>    public string Name { get; }<br>    public FieldInfo FieldInfo { get; }<br>    // etc...<br>}<br><br>var member = Fruits.Apple.ToMember();</pre><h4>2. Gets EnumMemberAttribute.Value</h4><p>I often see the developer using EnumMemberAttribute as an alias for field name. So FastEnum provides an API that the value can be quickly obtained from the EnumMemberAttribute.Value property.</p><pre>enum Company<br>{<br>    [EnumMember(Value = &quot;Apple, Inc.&quot;)]<br>    Apple = 0,<br>}<br><br>var value = Company.Apple.GetEnumMemberValue();  // Apple, Inc.</pre><h4>3. Adds multiple label annotations to a field</h4><p>Multiple attributes can’t be attached to the same field, since EnumMemberAttribute is specified AllowMultiple = false. It’s inconvenient and I don’t like it personally, so I often use my own LabelAttribute as an alternative. You can use it conveniently as follows, because FastEnum provides this feature.</p><pre>enum Company<br>{<br>    [Label(&quot;Apple, Inc.&quot;)]<br>    [Label(&quot;AAPL&quot;, 1)]<br>    Apple = 0,<br>}<br><br>var x1 = Company.Apple.GetLabel();   // Apple, Inc.<br>var x2 = Company.Apple.GetLabel(1);  // AAPL</pre><h3>Limitation</h3><h4>1. Provides only generics API</h4><p>FastEnum provides only generics version method because of performance reason. System.Enum provides System.Type argument overload, but that’s too slow because of boxing occuration. If you need to use the method that passes System.Type type, please use System.Enum version.</p><h4>2. Can’t parse comma-separated string</h4><p>System.Enum.Parse can parse like following string. I think that it isn’t well known because it is a specification that exists quietly.</p><pre>//--- Assuming there is an enum type like following...<br>[Flags]<br>enum Fruits<br>{<br>    Apple = 1,<br>    Lemon = 2,<br>    Melon = 4,<br>    Banana = 8,<br>}<br><br>//--- Passes comma-separated string<br>var value = Enum.Parse&lt;Fruits&gt;(&quot;Apple, Melon&quot;);<br>Console.WriteLine((int)value);  // 5</pre><p>It seems to be a useful function when performing flag processing, but if tries to add such a comma-separated analysis, the overhead will come out, so cutting this feature off makes speed up. I think that in most cases there is no problem, because this feature is rarely used (at least I have NEVER used for 12 years).</p><h3>Why fast ?</h3><p>As you might expect, it’s because cached internally. It takes the approach of <strong>Static Type Caching</strong>, so the reading cost is <strong>almost zero</strong>. Based on this, I use techniques for avoiding allocation, and create specialized dictionary for specific key internally.</p><h3>Conclusion</h3><p>The easiest way to write fast code is to use a fast library. This library will surely help you. Please try it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a616b9b2c901" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>