コード例 #1
0
ファイル: KnownTypes.cs プロジェクト: xeronith/BrainSimulator
        public override object Deserialize(XElement elem, XNamespace overridingNamespace)
        {
            var child = elem.Elements().FirstOrDefault();

            if (child == null)
            {
                return(null);
            }
            using (var xr = child.CreateReader())
            {
                var dsType = ReflectionUtils.GetTypeByName("System.Data.DataSet");
                var ds     = Activator.CreateInstance(dsType);
                ReflectionUtils.InvokeMethod(ds, "ReadXml", xr);
                return(ds);
            }
        }
コード例 #2
0
ファイル: XMLUtils.cs プロジェクト: diegobarbosa/YAXLib
        public static string ToXmlValue(this object self)
        {
            string typeName = self == null ? String.Empty : self.GetType().Name;

            switch (typeName)
            {
            case "Double":
                return(((double)self).ToString("R", YAXSerializer.CurrentCulture));

            case "Single":
                return(((Single)self).ToString("R", YAXSerializer.CurrentCulture));

            case "BigInteger":
                return(ReflectionUtils.InvokeMethod(self, "ToString", "R", YAXSerializer.CurrentCulture) as string);
            }
            return(Convert.ToString((self ?? String.Empty), YAXSerializer.CurrentCulture));
        }
コード例 #3
0
        public static string ToXmlValue(this object self)
        {
            var typeName = self == null ? string.Empty : self.GetType().Name;

            switch (typeName)
            {
            case "Double":
                return(((double)self).ToString("R", CultureInfo.InvariantCulture));

            case "Single":
                return(((float)self).ToString("R", CultureInfo.InvariantCulture));

            case "BigInteger":
                return(ReflectionUtils.InvokeMethod(self, "ToString", "R", CultureInfo.InvariantCulture) as string);
            }

            return(Convert.ToString(self ?? string.Empty, CultureInfo.InvariantCulture));
        }
コード例 #4
0
        /// <summary>
        /// Gets the string representation of the object, or <see cref="string.Empty"/> if the object is <see langword="null"/>.
        /// </summary>
        /// <param name="self">The object to get as a string.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use for culture-specific output.</param>
        /// <returns>The <see cref="CultureInfo"/>-aware string representation of the object, or <see cref="string.Empty"/> if the object is <see langword="null"/>.</returns>
        public static string ToXmlValue(this object self, CultureInfo culture)
        {
            if (self == null)
            {
                return(string.Empty);
            }

            switch (self.GetType().Name)
            {
            case "Boolean":
                return(((bool)self).ToString().ToLowerInvariant());

            case "Double":
                return(((double)self).ToString("R", culture));

            case "Single":
                return(((float)self).ToString("R", culture));

            case "BigInteger":
                return(ReflectionUtils.InvokeMethod(self, "ToString", "R", culture) as string);
            }

            return(Convert.ToString(self, culture));
        }