示例#1
0
        /// <summary>
        /// Converts the object into a List<MemoryItem>.
        /// </summary>
        /// <param name="obj">Expects this object to be the following List<object> where each object
        /// is a List<object> where each sub-object is Key,Value pair of Text, Value, Type</param>
        /// <param name="success"></param>
        /// <returns></returns>
        private static object ConvertToCalc(object obj, ref bool success, Calc_MainPage page)
        {
            success = false;

            // if there's no valid page to link to
            if (page == null)
            {
                return(null);
            }

            List <Calculator.MemoryItem> returnList = new List <MemoryItem>();

            try
            {
                List <object> firstList = obj as List <object>;

                foreach (object val in firstList)
                {
                    Dictionary <string, object> dict = val as Dictionary <string, object>;

                    // create a new item
                    MemoryItem mi = new MemoryItem();
                    mi.InitializeWindow(page);
                    mi.Text = dict[CalcState.Text.ToString()] as string;

                    // the first part is the value
                    mi.Value = (dict[CalcState.Value.ToString()] as string);
                    mi.Type  = (Calc_MainPage.CalcStateValues) int.Parse(dict[CalcState.Type.ToString()].ToString());

                    returnList.Add(mi);
                }

                success = true;
            }
            catch { return(null); }

            return(returnList);
        }