コード例 #1
0
ファイル: CScrapperBase.cs プロジェクト: ibnipun10/RateLo
        public void PopulateData(string strPropName, string strPropValue, ref ItemDescription objItem)
        {
            PropertyInfo[] props = objItem.GetType().GetProperties();
            foreach (PropertyInfo prop in props)
            {
                string Propname  = Utilities.GetConvertedPropertyName(prop.Name);
                object PropValue = prop.GetValue(objItem, null);

                if (Propname.CompareTo(strPropName) == 0 && PropValue == null)
                {
                    prop.SetValue(objItem, strPropValue, null);
                }
            }
        }
コード例 #2
0
        public void SetModelName(ref ItemDescription objItem)
        {
            PropertyInfo[] props = objItem.GetType().GetProperties();

            foreach (PropertyInfo prop in props)
            {
                if (prop.Name.Equals("Model_ID"))
                {
                    string value = (string)prop.GetValue(objItem, null);

                    if (value != null)
                    {
                        objItem.Model_Name = (string)prop.GetValue(objItem, null);
                    }
                    return;
                }
            }
        }
コード例 #3
0
ファイル: BestBuyInteractor.cs プロジェクト: ibnipun10/RateLo
        public static void DeserializeJson(string response, ref ItemDescription objItem)
        {
            var jss  = new JavaScriptSerializer();
            var dict = jss.Deserialize <Dictionary <string, dynamic> >(response);

            PropertyInfo[] props = objItem.GetType().GetProperties();

            ArrayList productArray = dict[Common.Common.JSON_PRODUCT_ATTRIBUTE_PRODUCTS];


            if (productArray == null || productArray.Count == 0)
            {
                throw new Exception("Unable to find any product");
            }

            Dictionary <string, dynamic> productDict = (Dictionary <string, dynamic>)productArray[0];

            ArrayList detailsArray = productDict[Common.Common.JSON_PRODUCT_ATTRIBUTE_DETAILS];


            if (detailsArray != null)
            {
                foreach (var detail in detailsArray)
                {
                    Dictionary <string, dynamic> detaildict = (Dictionary <string, dynamic>)detail;
                    string detailName = detaildict[Common.Common.JSON_PRODUCT_ATTRIBUTE_NAME];

                    foreach (PropertyInfo prop in props)
                    {
                        string Propname = GetConvertedPropertyName(prop.Name);
                        if (detailName.CompareTo(Propname) == 0)
                        {
                            prop.SetValue(objItem, detaildict[Common.Common.JSON_PRODUCT_ATTRIBUTE_VALUE], null);
                            break;
                        }
                    }
                }
            }

            foreach (PropertyInfo prop in props)
            {
                string Propname = GetConvertedPropertyName(prop.Name);
                string value    = null;
                if (!productDict.ContainsKey(Propname))
                {
                    continue;
                }

                if (Propname.CompareTo(Common.Common.JSON_PRODUCT_ATTRIBUTE_FEATURES) == 0)
                {
                    ArrayList featureArray = productDict[Common.Common.JSON_PRODUCT_ATTRIBUTE_FEATURES];
                    string    featureValue = String.Empty;
                    foreach (var feature in featureArray)
                    {
                        Dictionary <string, dynamic> featuredict = (Dictionary <string, dynamic>)feature;

                        featureValue += featuredict[Common.Common.JSON_PRODUCT_ATTRIBUTE_FEATURE];
                    }

                    value = featureValue;
                }
                else
                {
                    value = "" + productDict[Propname];
                }

                if (value == null)
                {
                    continue;
                }

                if (prop.PropertyType == typeof(int))
                {
                    prop.SetValue(objItem, Convert.ToInt32(value), null);
                }
                else if (prop.PropertyType == typeof(float))
                {
                    prop.SetValue(objItem, Convert.ToSingle(value), null);
                }
                else if (prop.PropertyType == typeof(bool))
                {
                    prop.SetValue(objItem, Convert.ToBoolean(value), null);
                }
                else
                {
                    prop.SetValue(objItem, value, null);
                }
            }
        }