Esempio n. 1
0
        public static Dictionary <string, object> GetPropertyValues <T>(T source, SFClass.ObjectPropertyAccessType access)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if ((object)source == null)
            {
                return(dictionary);
            }
            foreach (PropertyInfo property in source.GetType().GetProperties())
            {
                try
                {
                    bool flag = false;
                    if (access == SFClass.ObjectPropertyAccessType.ReadWrite && property.CanRead && property.CanWrite)
                    {
                        flag = true;
                    }
                    if (access == SFClass.ObjectPropertyAccessType.ReadOnly && property.CanRead && !property.CanWrite)
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        string name = property.Name;
                        object obj  = property.GetValue((object)source, (object[])null);
                        dictionary.Add(name, obj);
                    }
                }
                catch
                {
                }
            }
            return(dictionary);
        }
Esempio n. 2
0
        public static string PropertyValuesToString(object source, SFClass.ObjectPropertyAccessType access, string delimiter = ":")
        {
            if (source == null)
            {
                return("");
            }
            Dictionary <string, string> propertyStringValues = SFClass.GetPropertyStringValues(source, access);

            if (propertyStringValues == null || propertyStringValues.Count <= 0)
            {
                return("");
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (string key in propertyStringValues.Keys)
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(delimiter);
                }
                stringBuilder.Append(key).Append(";").Append(propertyStringValues[key]);
            }
            return(stringBuilder.ToString());
        }