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


C# ClassInfo.AddUsing方法代码示例

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


在下文中一共展示了ClassInfo.AddUsing方法的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;
        }
开发者ID:RDunkley,项目名称:XML-To-Data-Class,代码行数:76,代码来源:ElementInfo.cs


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