本文整理汇总了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;
}
}
}
示例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;
}
示例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;
}