当前位置: 首页>>代码示例>>C#>>正文


C# PropertyDescriptor.GetChildProperties方法代码示例

本文整理汇总了C#中System.ComponentModel.PropertyDescriptor.GetChildProperties方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDescriptor.GetChildProperties方法的具体用法?C# PropertyDescriptor.GetChildProperties怎么用?C# PropertyDescriptor.GetChildProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.PropertyDescriptor的用法示例。


在下文中一共展示了PropertyDescriptor.GetChildProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetList

 /// <summary>
 /// 
 /// </summary>
 /// <param name="parentPD"></param>
 /// <param name="list"></param>
 private void GetList(PropertyDescriptor parentPD,ref IList list)
 {
     PropertyDescriptorCollection childPDs = parentPD.GetChildProperties();
     // if childPDs count < 0 then return
     if(childPDs.Count<=0 )
     {
         return;
     }
     // if parentPD is immultable type then return
     Type parentType = parentPD.PropertyType;
     if(    parentType.Name.Equals("String")
         || parentType.Name.Equals("Int32")
         || parentType.Name.Equals("Int64")
         || parentType.Name.Equals("Float")
         || parentType.Name.Equals("Double")
         || parentType.Name.Equals("Boolean")
         || parentType.Name.Equals("DateTime"))
     {
         return;
     }
     foreach (PropertyDescriptor childPD in childPDs)
     {
         ComplexPropertyDescriptor subPropertyDescriptor = new ComplexPropertyDescriptor(parentPD, childPD, parentPD.Name + "." + childPD.Name);
         if (PropertyDescriptorNotInList((PropertyDescriptor)subPropertyDescriptor, list))
         {
             list.Add(subPropertyDescriptor);
         }
         PropertyDescriptorCollection subChildPDs = childPD.GetChildProperties();
         if(subChildPDs.Count> 0 )
         {
             GetList(childPD,ref list);
         }
         else
         {
             return;
         }
     }
 }
开发者ID:DelLitt,项目名称:opmscoral,代码行数:43,代码来源:ComplexCustomTypeDescriptor.cs

示例2: ProcessAttribute

        /// <summary>
        /// Writes an attribute to an HtmlTextWriter if it needs serializing
        /// </summary>
        /// <returns>True if it does any writing</returns>
        private static bool ProcessAttribute(PropertyDescriptor prop, object o, HtmlTextWriter writer, string prefix)
        {
            //check whether we're serialising it
            if (prop.SerializationVisibility == DesignerSerializationVisibility.Hidden
                || prop.DesignTimeOnly
                || prop.IsReadOnly
                || !prop.ShouldSerializeValue (o)
                || prop.Converter == null
                || !prop.Converter.CanConvertTo (typeof(string)))
                return false;

            bool foundAttrib = false;

            //is this an attribute? If it's content, we deal with it later.
            PersistenceModeAttribute modeAttrib = prop.Attributes[typeof (PersistenceModeAttribute)] as PersistenceModeAttribute;
            if (modeAttrib == null || modeAttrib.Mode == PersistenceMode.Attribute)
            {
                if (prop.SerializationVisibility == DesignerSerializationVisibility.Visible) {
                    if (prefix == string.Empty)
                        writer.WriteAttribute (prop.Name, prop.Converter.ConvertToString (prop.GetValue (o)));
                    else
                        writer.WriteAttribute (prefix + "-" + prop.Name, prop.Converter.ConvertToString (prop.GetValue(o)));
                    foundAttrib = true;
                }
                //recursively handle subproperties
                else if (prop.SerializationVisibility == DesignerSerializationVisibility.Content) {
                    object val = prop.GetValue (o);
                    foreach (PropertyDescriptor p in prop.GetChildProperties (val))
                        if (ProcessAttribute (p, val, writer, prop.Name))
                            foundAttrib = true;
                }
            }
            return foundAttrib;
        }
开发者ID:mono,项目名称:aspeditor,代码行数:38,代码来源:ControlPersister.cs

示例3: ProcessAttribute

		/// <summary>
		/// Writes an attribute to an HtmlTextWriter if it needs serializing
		/// </summary>
		/// <returns>True if it does any writing</returns>
		private static bool ProcessAttribute (PropertyDescriptor prop, object o, HtmlTextWriter writer, string prefix)
		{
			//FIXME: there are several NotImplementedExceptions in Mono's ASP.NET 2.0
			//this is a hack so it doesn't break when encountering them
			try {
				prop.GetValue (o);
			} catch (Exception ex) {
				if ((ex is NotImplementedException) || (ex.InnerException is NotImplementedException))
					return false;
				else
					throw;
			}
			
			//FIXME: Mono has started to return prop.ShouldSerializeValue = false for ID
			//workaround, because I'm not sure if this is expected behaviour, and it would still be 
			//broken for some people's runtime
			if (prop.DisplayName == "ID") {
				writer.WriteAttribute ("id", prop.GetValue (o) as string);
				return true;
			}
			
			//check whether we're serialising it
			if (prop.SerializationVisibility == DesignerSerializationVisibility.Hidden
				|| prop.DesignTimeOnly
				|| prop.IsReadOnly
				|| !prop.ShouldSerializeValue (o)
				|| prop.Converter == null
				|| !prop.Converter.CanConvertTo (typeof(string)))
				return false;
			
			bool foundAttrib = false;
				
			//is this an attribute? If it's content, we deal with it later.		
			PersistenceModeAttribute modeAttrib = prop.Attributes[typeof (PersistenceModeAttribute)] as PersistenceModeAttribute;
			if (modeAttrib == null || modeAttrib.Mode == PersistenceMode.Attribute)
			{
				if (prop.SerializationVisibility == DesignerSerializationVisibility.Visible) {
					if (prefix == string.Empty)
						writer.WriteAttribute (prop.Name, prop.Converter.ConvertToString (prop.GetValue (o)));
					else
						writer.WriteAttribute (prefix + "-" + prop.Name, prop.Converter.ConvertToString (prop.GetValue(o)));
					foundAttrib = true;
				}
				//recursively handle subproperties
				else if (prop.SerializationVisibility == DesignerSerializationVisibility.Content) {
					object val = prop.GetValue (o);
					foreach (PropertyDescriptor p in prop.GetChildProperties (val))
						if (ProcessAttribute (p, val, writer, prop.Name))
							foundAttrib = true;
				}
			}
			return foundAttrib;
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:57,代码来源:ControlPersister.cs


注:本文中的System.ComponentModel.PropertyDescriptor.GetChildProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。