Thursday, 28 July 2016

Getting enum values to list of string List<string> C#

So you created an enum and you want to extract all the values to List<string>?

Example enum:


public enum FilterTypeLookup {
Textbox = 1,
Standard_Dropdown = 2,
Extended_Dropdown = 3,
Normal_Dropdown = 4,
Link = 5,
Label = 6,
Checkbox = 7,
Dropdown_with_Textbox_and_Button = 8,
Textbox_with_text_before_and_text_after = 9,
Radio_Button = 10,
Date_Picker = 11,
Month = 12,
Year = 13,
Customer_Dropdown = 14,
AutoComplete = 15
}

Probably the easiest way to do it is to use GetNames method on Enum.

return Enum.GetNames(typeof(FilterTypeLookup )).ToList();


If we want to make it more generic we can write helper method.

 public static List<string> GetNamesForEnums<T>()
        {
            //Type type = t.GetType();
            return Enum.GetNames(typeof(T)).ToList();
        }



Wednesday, 20 July 2016

PBR Wood Textures Pack

Recently I released PBR Wood texture for Unity 3d store. Each material will contain at least 4 textures(albedo, normal, ambient oclusion, height). Some material will also contain gloss and metallic texture. All textures are seamless and at least 1024x1024 px.

You can grab them at Unity store

For last 2 months it is top paid wood texture pack.












Monday, 18 July 2016

Adding multiple appSettings to webConfig file and getting value in ASP.MET MVC

Let's say we want to add few app settings file to a webconfig file, so if we have to change value of the key on the server, IIS does not have to recompile the whole application leading to better client/customer experience.

1. In webconfig add new section.

<configuration>
<configsections>

<section name="DatabaseConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</section>
</configsections>
...


2. Create new config file in solution, let's call it CodeBasedOnReferer.config.
3. Add new key

<DatabaseConfig>
    <add key="google.com" value="Google_123"></add>
</DatabaseConfig>

4. To obtain the code in aplication in controller:

NameValueCollection settings = (NameValueCollection) ConfigurationManager.GetSection("DatabaseConfig");
string code = settings (Request.UrlReferrer.Authority);

5. You can test your application using for instance fiddler. To create request open fiddler. Just in case you do not have it : http://www.telerik.com/fiddler


6. Your code should be Google_123.