Exemplo n.º 1
0
        /// <summary>
        /// Returns the enum SiteConf.Model based on object type.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static SiteConf.Model GetModelFromObj(ObjectAbstract obj)
        {
            Type type = obj.GetType();

            if (type == typeof(SiteConf.DiseaseTag.Object))
                return Model.diseasetag;

            if (type == typeof(SiteConf.Gene.Object))
                return Model.gene;

            if (type == typeof(SiteConf.HVPTran.Object))
                return Model.hvptran;

            if (type == typeof(SiteConf.OrgSite.Object))
                return Model.orgsite;

            if (type == typeof(SiteConf.Upload.Object))
                return Model.upload;
            else
                throw new Exception("Can not find object within SiteConf.Model");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes standard object to JObject
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static JObject JObjectSerializer(ObjectAbstract obj)
        {
            JObject jObj = new JObject();

            Type type = obj.GetType();
            IList<System.Reflection.PropertyInfo> props =
                new List<System.Reflection.PropertyInfo>(type.GetProperties());
            foreach (System.Reflection.PropertyInfo prop in props)
            {
                string propName = prop.Name;
                // ignore "ID" and "resource_uri" fields
                if (propName == "ID" || propName == "resource_uri")
                    continue;
                else
                {
                    object propValue = prop.GetValue(obj, null);
                    // do not append to json if value is null
                    if (propValue != null)
                        jObj.Add(propName, propValue.ToString());
                }
            }

            return jObj;
        }