示例#1
0
        /// <summary>
        /// set property value to destiny object
        /// </summary>
        /// <param name="pi">prpperty info</param>
        /// <param name="destiny">destiny object</param>
        /// <param name="value">value</param>
        private static void SetPropertyValue(PropertyInfo pi, object destiny, object value)
        {
            if (pi == null || destiny == null)
            {
                return;
            }
            string type = pi.PropertyType.ToString();

            type = Regex.Match(type, type.IndexOf("[") > -1 ? @"(?<=\[\w+\.)[^\]]+" : @"(?<=\.)\w+").Value;
            switch (type)
            {
            case "Boolean": pi.SetValue(destiny, Boolean.Parse(ConvertTool.GetString(value)), null); break;

            case "Byte": pi.SetValue(destiny, Byte.Parse(ConvertTool.GetString(value)), null); break;

            case "Decimal": pi.SetValue(destiny, Decimal.Parse(ConvertTool.GetString(value)), null); break;

            case "Double": pi.SetValue(destiny, Double.Parse(ConvertTool.GetString(value)), null); break;

            case "DateTime": pi.SetValue(destiny, DateTime.Parse(ConvertTool.GetString(value)), null); break;

            case "Int16": pi.SetValue(destiny, Int16.Parse(ConvertTool.GetString(value)), null); break;

            case "Int32": pi.SetValue(destiny, Int32.Parse(ConvertTool.GetString(value)), null); break;

            case "Int64": pi.SetValue(destiny, Int64.Parse(ConvertTool.GetString(value)), null); break;

            case "Single": pi.SetValue(destiny, Single.Parse(ConvertTool.GetString(value)), null); break;

            //case "Entity":; break;
            default: pi.SetValue(destiny, value, null); break;
            }
        }
示例#2
0
        /// <summary>
        /// get node value from the xml file by xpath
        /// </summary>
        /// <param name="xpath">xml xpath</param>
        /// <param name="targetXml">xml file full path or xml content</param>
        /// <param name="useCache">is use the cache</param>
        /// <param name="updateForce">force update the cache</param>
        /// <returns>node value</returns>
        public static string GetNodeValueByXPath(string xpath, string targetXml = null, bool useCache = true, bool updateForce = true)
        {
            if (string.IsNullOrEmpty(xpath))
            {
                LogTool.Info("xpath is not defined");
                return(string.Empty);
            }
            targetXml = string.IsNullOrEmpty(targetXml) ? _defaultXmlPath : targetXml;
            string        res       = string.Empty;
            StringBuilder sbCombine = new StringBuilder();

            sbCombine.Append(xpath);
            sbCombine.Append(targetXml);
            string cacheKey = sbCombine.ToString().GetHashCode().ToString();

            try
            {
                if (useCache)
                {
                    if (CacheTool.Exists(cacheKey))
                    {
                        if (updateForce)
                        {
                            res = GetValueByXPath(xpath, targetXml);
                            CacheTool.SetCache(cacheKey, res, 30);
                        }
                        else
                        {
                            res = ConvertTool.GetString(CacheTool.GetCache(cacheKey));
                        }
                    }
                    else
                    {
                        res = GetValueByXPath(xpath, targetXml);
                        CacheTool.SetCache(cacheKey, res, 30);
                    }
                }
                else
                {
                    res = GetValueByXPath(xpath, targetXml);
                }
            }
            catch (Exception ex)
            {
                LogTool.Error(ex);
            }
            return(res);
        }
示例#3
0
        /// <summary>
        /// compare property object value
        /// </summary>
        /// <param name="tmpA">property value 1</param>
        /// <param name="tmpB">property value 1</param>
        /// <param name="pi">property info</param>
        /// <returns>compare result</returns>
        private static bool CompareValue(object tmpA, object tmpB, PropertyInfo pi)
        {
            if (tmpA == null || tmpB == null)
            {
                return(false);
            }
            if (pi == null)
            {
                return(false);
            }
            string type = pi.PropertyType.ToString();

            type = Regex.Match(type, type.IndexOf("[") > -1 ? @"(?<=\[\w+\.)[^\]]+" : @"(?<=\.)\w+").Value;
            switch (type)
            {
            case "Boolean":
                return(ConvertTool.GetBool(tmpA) == ConvertTool.GetBool(tmpB));

            case "Byte":
                return(ConvertTool.GetByte(tmpA) == ConvertTool.GetByte(tmpB));

            case "Decimal": return(ConvertTool.GetDecimal(tmpA) == ConvertTool.GetDecimal(tmpB));

            case "Double": return(ConvertTool.GetDouble(tmpA) == ConvertTool.GetDouble(tmpB));

            case "DateTime": return(ConvertTool.GetDateTime(tmpA) == ConvertTool.GetDateTime(tmpB));

            case "Int16": return(ConvertTool.GetShort(tmpA) == ConvertTool.GetShort(tmpB));

            case "Int32": return(ConvertTool.GetInt(tmpA) == ConvertTool.GetInt(tmpB));

            case "Int64": return(ConvertTool.GetLong(tmpA) == ConvertTool.GetLong(tmpB));

            case "Single": return(ConvertTool.GetFloat(tmpA) == ConvertTool.GetFloat(tmpB));

            case "String": return(ConvertTool.GetString(tmpA) == ConvertTool.GetString(tmpB));

            //case "Entity":; break;
            default: return(false);
            }
        }