Exemple #1
0
        public static T GetValueFromCard <T>(this BaseCard card, string sectionAlias, string fieldAlias)
        {
            T result = default(T);
            BaseCardSectionRow sectionRow = card.GetSectionRow(sectionAlias);

            if (sectionRow != null)
            {
                object value = sectionRow[fieldAlias];
                if (value is T)
                {
                    result = (T)value;
                }
                else if (value is IConvertible)
                {
                    IConvertible converteble = value as IConvertible;
                    result = (T)converteble.ToType(typeof(T), CultureInfo.InvariantCulture);
                    //result = (T)(object)sectionRow[fieldAlias];
                }
                else if (value != null)
                {
                    string message = string.Format("Can't convert value of type '{0}' to type '{1}'", value.GetType().Name, typeof(T).Name);
                    throw new InvalidOperationException(message);
                }
            }
            return(result);
        }