Пример #1
0
        public static T ConvertDictionaryToEntity <T>(IDictionary <string, object> dict)
        {
            T val = Activator.CreateInstance <T>();

            PropertyInfo[] properties = val.GetType().GetProperties();
            if (properties.Length != 0 && ((ICollection <KeyValuePair <string, object> >)dict).Count > 0)
            {
                PropertyInfo[] array = properties;
                foreach (PropertyInfo propertyInfo in array)
                {
                    MethodInfo getMethod = propertyInfo.GetGetMethod();
                    if (dict.ContainsKey(propertyInfo.Name))
                    {
                        string name  = propertyInfo.Name;
                        string value = dict[propertyInfo.Name].ToNullString();
                        try
                        {
                            if (propertyInfo.CanWrite)
                            {
                                propertyInfo.SetValue(val, string.IsNullOrEmpty(value) ? ((propertyInfo.PropertyType == typeof(string)) ? "" : DataHelper.DefaultForType(propertyInfo.PropertyType)) : Convert.ChangeType(value, propertyInfo.PropertyType), null);
                            }
                        }
                        catch (Exception ex)
                        {
                            IDictionary <string, string> dictionary = new Dictionary <string, string>();
                            dictionary.Add("key", name);
                            dictionary.Add("value", value);
                            Globals.WriteExceptionLog(ex, dictionary, "ConvertException");
                        }
                    }
                }
            }
            return(val);
        }
Пример #2
0
 public static Bitmap GetNetImg(string imgUrl)
 {
     try
     {
         Random random = new Random();
         imgUrl = ((!imgUrl.Contains("?")) ? (imgUrl + "?aid=" + random.NextDouble()) : (imgUrl + "&aid=" + random.NextDouble()));
         WebRequest  webRequest     = WebRequest.Create(imgUrl);
         WebResponse response       = webRequest.GetResponse();
         Stream      responseStream = response.GetResponseStream();
         Image       image          = Image.FromStream(responseStream);
         responseStream.Close();
         responseStream.Dispose();
         webRequest = null;
         response   = null;
         return((Bitmap)image);
     }
     catch (Exception ex)
     {
         IDictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("NetImgUrl", imgUrl);
         Globals.WriteExceptionLog(ex, dictionary, "SplittinRuleGetNetImg");
         return(new Bitmap(100, 100));
     }
 }