Taylohtio/AlertManager/SPSolutions.SharePoint.Aler.../SPSolutions.Common/SPSolutions/IntegerUtil.cs

39 lines
885 B
C#

using System;
using System.Collections.Generic;
namespace SPSolutions
{
public class IntegerUtil
{
public static int GetFirstValidInteger(object[] potentialIntegers, int defaultValue)
{
List<string> list = new List<string>();
for (int i = 0; i < potentialIntegers.Length; i++)
{
object obj = potentialIntegers[i];
if (obj != null)
{
if (obj is int)
{
return (int)obj;
}
list.Add(obj.ToString());
}
}
return IntegerUtil.GetFirstValidInteger(list.ToArray(), defaultValue);
}
public static int GetFirstValidInteger(string[] potentialIntegers, int defaultValue)
{
for (int i = 0; i < potentialIntegers.Length; i++)
{
string text = potentialIntegers[i];
int result;
if (!string.IsNullOrEmpty(text) && int.TryParse(text, out result))
{
return result;
}
}
return defaultValue;
}
}
}