Sitecore Field Utilities

Sitecore utilities to convert a boolean and an INT in sitecore

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public class Converter
{
    public static bool BooleanParser(string value)
    {
      return value.Equals("1");
      }

      public static int GetSafeInt(Item item,string fieldName)
        {
            var itemVlaue = item[fieldName];

            if (!String.IsNullOrWhiteSpace(itemVlaue))
            {
                var intResult = 0;
                if (Int32.TryParse(itemVlaue, out intResult))
                {
                    return intResult;
                }
            }
            return 0;
        }

}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s