コード例 #1
0
        /// <summary>
        ///     Returns null if no properties are found.
        /// </summary>
        /// <param name="objectType">Type of any object/class/</param>
        /// <returns>Returns the list of properties with values in the class.</returns>
        public static List<ObjectProperty> GetPropertiesValues(this object objectType)
        {
            var listOfPropertise = new List<ObjectProperty>(100);
            if (objectType != null) {
                var properties = objectType.GetType().GetProperties(TypeOfPropertise).ToList();

                if (properties != null && properties.Count > 0) {
                    foreach (var prop in properties) {
                        var property = new ObjectProperty {
                            Name = prop.Name,
                            Value = prop.GetValue(objectType, null)
                        };
                        listOfPropertise.Add(property);
                    }
                    return listOfPropertise;
                }
            }

            return null;
        }
コード例 #2
0
        /// <summary>
        ///     Generates any class to ObjectProperty data type
        /// </summary>
        /// <param name="Class">Give any class object to retrieve it's property and values.</param>
        /// <returns></returns>
        public static List<ObjectProperty> Get(object Class)
        {
            if (Class != null) {
                var propertise =
                    Class.GetType()
                        .GetProperties(TypeOfPropertise)
                        .Where(p => /* p.Name != "EntityKey" &&*/ p.Name != "EntityState");

                var list = new List<ObjectProperty>(propertise.Count());
                foreach (var prop in propertise) {
                    var val = prop.GetValue(Class, null);
                    var propertyName = prop.Name;
                    var obj = new ObjectProperty {
                        Name = propertyName,
                        Value = val
                    };
                    list.Add(obj);
                }
                return list;
            }
            return null;
        }