public GetChildProperties ( ) : |
||
return |
/// <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; } } }
/// <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; }
/// <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; }