本文整理汇总了C#中ClassInfo.AddChildClass方法的典型用法代码示例。如果您正苦于以下问题:C# ClassInfo.AddChildClass方法的具体用法?C# ClassInfo.AddChildClass怎么用?C# ClassInfo.AddChildClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassInfo
的用法示例。
在下文中一共展示了ClassInfo.AddChildClass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateDataClass
public ClassInfo GenerateDataClass(bool preserveHierarchy)
{
ClassInfo info = new ClassInfo("public partial", ClassName, null, string.Format("In memory representation of the XML element \"{0}\".", Name));
info.AddUsing("System.Xml");
info.AddUsing("System.IO");
List<DataInfo> dataList = new List<DataInfo>();
// Add text property.
if (Text.Include)
dataList.Add(Text.Info);
// Add CDATA property.
if (CDATA.Include)
dataList.Add(CDATA.Info);
// Add properties to represent the attributes.
foreach (AttributeInfo attrib in Attributes)
dataList.Add(attrib.Info);
foreach(DataInfo data in dataList)
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("Gets or sets the value of the child {0} element.", data.Name));
if(data.SelectedDataType == DataType.String)
{
if (data.IsOptional)
sb.Append(" Can be null.");
if (data.CanBeEmpty)
sb.Append(" Can be empty.");
}
else
{
if (data.IsOptional || data.CanBeEmpty)
sb.Append(" Can be null.");
}
info.Properties.Add(new PropertyInfo("public", data.GetDataTypeString(), data.PropertyName, sb.ToString()));
// Add any additional properties.
info.Properties.AddRange(data.SelectedDataTypeObject.GenerateAdditionalProperties());
// Add any additional enums.
info.Enums.AddRange(data.SelectedDataTypeObject.GenerateAdditionalEnums());
// Add any custom usings.
info.AddUsings(data.GetSelectedUsings());
}
// Add properties to represent the child nodes.
foreach (ElementInfo child in Children)
{
string summary = "Gets or sets the child XML elements.";
info.Properties.Add(new PropertyInfo("public", string.Format("{0}[]", child.ClassName), GenerateChildArrayNameProperty(child.ClassName), summary, null, null, "private"));
}
// Create the constructors.
info.Constructors.Add(GenerateDataClassConstructor());
info.Constructors.Add(GenerateDataClassXmlNodeConstructor());
// Add additional methods.
info.Methods.AddRange(GenerateMethods(dataList.ToArray()));
info.Methods.Add(GenerateCreateElementMethod());
if(preserveHierarchy)
{
// Add additional sub-classes.
foreach (ElementInfo child in Children)
{
ClassInfo childClass = child.GenerateDataClass(preserveHierarchy);
info.AddChildClass(childClass);
}
}
return info;
}