/// <summary>
        /// Writes an item or property in Monad namespace
        /// </summary>
        /// <param name="serializer">The serializer to which the object is serialized.</param>
        /// <param name="property">name of property. Pass null for item</param>
        /// <param name="source">object to be written</param>
        /// <param name="entry">serialization information about source</param>
        /// <param name="result"></param>
        private static void CreateCimInstanceForOnePrimitiveKnownType
        (
            InternalMISerializer serializer,
            string property,
            object source,
            MITypeSerializationInfo entry,
            out CimInstance result
        )
        {
            Dbg.Assert(serializer != null, "caller should have validated the information");
            Dbg.Assert(source != null, "caller should have validated the information");
            Dbg.Assert(entry != null, "caller should have validated the information");

            if (entry != null && entry.Serializer == null)
            {
                // we are not using GetToString, because we assume that
                // ToString() for primitive types never throws
                string value = Convert.ToString(source, CultureInfo.InvariantCulture);
                Dbg.Assert(value != null, "ToString shouldn't return null for primitive types");
                result = CreateRawStringCimInstance(property, value, entry);
            }
            else
            {
                result = entry.Serializer(property, source, entry);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Writes an item or property in Monad namespace
        /// </summary>
        /// <param name="serializer">The serializer to which the object is serialized.</param>
        /// <param name="property">name of property. Pass null for item</param>
        /// <param name="source">object to be written</param>
        /// <param name="entry">serialization information about source</param>
        /// <param name="result"></param>
        private static void CreateCimInstanceForOnePrimitiveKnownType
        (
            InternalMISerializer serializer,
            string property,
            object source,
            MITypeSerializationInfo entry,
            out CimInstance result
        )
        {
            Dbg.Assert(serializer != null, "caller should have validated the information");
            Dbg.Assert(source != null, "caller should have validated the information");
            Dbg.Assert(entry != null, "caller should have validated the information");

            if (entry != null && entry.Serializer == null)
            {
                // we are not using GetToString, because we assume that
                // ToString() for primitive types never throws
                string value = Convert.ToString(source, CultureInfo.InvariantCulture);
                Dbg.Assert(value != null, "ToString shouldn't return null for primitive types");
                result = CreateRawStringCimInstance(property, value, entry);
            }
            else
            {
                result = entry.Serializer(property, source, entry);
            }
        }