Ejemplo n.º 1
0
 /// <summary>
 /// 添加属性到类型的实例,注意:该操作会将其它成员清除掉,其功能有待完善。
 /// </summary>
 /// <param name="classType">指定类型的实例。</param>
 /// <param name="customProperty">表示一个属性。</param>
 /// <returns>返回处理过的类型的实例。</returns>
 public static Type AddProperty(Type classType, CustomPropertyInfo customProperty)
 {
     List<CustomPropertyInfo> listCustomPropertyInfo = new List<CustomPropertyInfo>();
     listCustomPropertyInfo.Add(customProperty);
     //合并先前的属性,以便一起在下一步进行处理。
     MergeProperty(classType, listCustomPropertyInfo);
     //把属性加入到Type。
     return AddPropertyToType(classType, listCustomPropertyInfo);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 从类型的实例t的属性移除属性列表lcpi,返回的新属性列表在lcpi中。
        /// </summary>
        /// <param name="t">类型的实例t。</param>
        /// <param name="listProperties">要移除的属性列表。</param>
        private static List<CustomPropertyInfo> SeparateProperty(Type t, List<string> listProperties)
        {
            List<CustomPropertyInfo> listCustomPropertyInfo = new List<CustomPropertyInfo>();
            foreach (PropertyInfo propertyInfo in t.GetProperties())
            {
                foreach (string s in listProperties)
                {
                    if (propertyInfo.Name != s)
                    {
                        CustomPropertyInfo cpi = new CustomPropertyInfo(propertyInfo.PropertyType.FullName, propertyInfo.Name);
                        listCustomPropertyInfo.Add(cpi);
                    }
                }
            }

            return listCustomPropertyInfo;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 把类型的实例t和lcpi参数里的属性进行合并。
 /// </summary>
 /// <param name="t">实例t</param>
 /// <param name="listCustomPropertyInfo">里面包含属性列表的信息。</param>
 private static void MergeProperty(Type t, List<CustomPropertyInfo> listCustomPropertyInfo)
 {
     foreach (PropertyInfo propertyInfo in t.GetProperties())
     {
         CustomPropertyInfo customPropertyInfo = new CustomPropertyInfo(propertyInfo.PropertyType.FullName, propertyInfo.Name);
         listCustomPropertyInfo.Add(customPropertyInfo);
     }
 }