Beispiel #1
0
        /// <summary>
        /// Create a session state for the tests
        /// </summary>
        /// <param name="st">The session content to populate with test data.</param>
        public void CreateSessionState(AspSessionContents st)
        {
            // Tableau
            object[] array = new object[3];
            array[0] = "Yanal";
            array[1] = "Joe";
            array[2] = "Simon";
            st.Add("keyarray", array);

            // Bool
            st.Add("keybool", true);

            // SingedByte
            sbyte sbyt = -12;

            st.Add("KeySignedByte", sbyt);

            // Unsigned byte
            byte byt = 12;

            st.Add("keybyte", byt);
            st.Add("keycur", new Currency(543));
            st.Add("keydate", new DateTime(1962, 10, 19));

            // double
            double doub = 3.23454;

            st.Add("keydbl", doub);

            // UnsingedShort"
            st["KeyUshort"] = (ushort)13;

            // Short
            short myshort = 12;

            st.Add("keyint", myshort);

            // UnsingedInteger
            st["KeyUInt"] = (uint)2434;

            // SingedInteger
            int myint = 25427;

            st.Add("keylng", myint);
            st.Add("keynull", null);

            // Single
            float mysing = 75.34211F;

            st.Add("keysng", mysing);

            // Decimal
            st["KeyDecimal"] = (decimal)234.456;

            // Date
            st.Add("keytime", new DateTime(1899, 12, 30, 04, 35, 47));

            // Empty
            st["keyempty"] = new AspEmpty();
        }
        /// <summary>
        /// deserialize un element xml en type associé
        /// </summary>
        /// <param name="element">element xml</param>
        /// <returns>The deserialized object</returns>
        private object DeserializeFromType(XElement element)
        {
            string type = element.Attribute("TypeName").Value;
            object myObject;

            switch (type)
            {
            case "SingedByte":
                myObject = SByte.Parse(element.Value);
                break;

            case "UnsingedByte":
                myObject = Byte.Parse(element.Value);
                break;

            case "SingedShort":
                myObject = short.Parse(element.Value);
                break;

            case "SingedInteger":
                myObject = Int32.Parse(element.Value);
                break;

            case "UnsingedShort":
                myObject = ushort.Parse(element.Value);
                break;

            case "UnsingedInteger":
                myObject = UInt32.Parse(element.Value);
                break;

            case "SingedMachineInteger":
                myObject = int.Parse(element.Value);
                break;

            case "UnsingedMachineInteger":
                myObject = uint.Parse(element.Value);
                break;

            case "Decimal":
                myObject = decimal.Parse(element.Value);
                break;

            case "Real4":
                myObject = float.Parse(element.Value);
                break;

            case "Real8":
                myObject = double.Parse(element.Value);
                break;

            case "Bool":    // Le bool.parse ne marche que sur true ou false. dans la base ici on aura une valeur numérique
                myObject = System.Convert.ToBoolean(int.Parse(element.Value));
                break;

            case "Currency":
                myObject = new Currency(decimal.Parse(element.Value));
                break;

            case "Date":
                myObject = DateTime.Parse(element.Value);
                break;

            case "Null":
                myObject = null;
                break;

            case "Empty":
                myObject = new AspEmpty();
                break;

            case "String":
                myObject = element.Value;
                break;

            default:
                myObject = null;
                Loggers.Logger.Error("try to deserialize unknown type");
                break;
            }

            return(myObject);
        }