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


C# CodeCompileUnit.CreateNamespace方法代码示例

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


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

示例1: GenerateTemplateCode

        /// <summary>
        /// Generates code representing a set of Sitecore templates
        /// </summary>
        private void GenerateTemplateCode(CodeCompileUnit concreteUnit, CodeCompileUnit interfaceUnit)
        {
            CodeNamespace interfaceNamespace = interfaceUnit.CreateNamespace(Parameters.InterfaceNamespace);

            var templatesToGenerate = new List<TemplateGenerationInfo>(Templates); // as interface generation can modify the Templates collection, we need to make an immutable copy of the collection items before we iterate over it

            foreach (var template in templatesToGenerate)
            {
                // setup concrete model object
                CodeNamespace templateNamespace = GetTemplateNamespace(concreteUnit, template.Template.ID, Parameters.ItemNamespace);
                CodeTypeDeclaration concrete = templateNamespace.CreateType(MemberAttributes.Public, template.TypeName.AsIdentifier());
                concrete.IsClass = true;
                concrete.IsPartial = true;
                concrete.BaseTypes.Add(new CodeTypeReference(Parameters.ItemBaseClass, CodeTypeReferenceOptions.GlobalReference));

                // add the constructor (validates item template)
                concrete.Members.AddRange(CreateItemConstructors());

                AddGeneratedCodeAttributeToType(concrete);
                AddTemplateIdPropertiesToEntity(concrete, template.Template); // adds static and dynamic template ID property
                AddCommentsToItem(concrete, template.Template); // adds XML comments based on Sitecore Help fields

                HashSet<string> fieldKeys = GetBaseFieldSet();
                fieldKeys.Add(concrete.Name); // member names cannot be the same as their enclosing type so we add the type name to the fields collection
                foreach (var baseTemplate in template.AllNonstandardBaseTemplates) // similarly names can't be the same as any of their base templates' names (this would cause an incompletely implemented interface)
                    fieldKeys.Add(baseTemplate.Template.Name.AsIdentifier());		// NOTE: you could break this if you have a base template called Foo and a field called Foo that IS NOT on the Foo template (but why would you have that?)

                // generate item properties
                foreach (var field in template.Template.Fields)
                {
                    if (_templateInputProvider.IsFieldIncluded(field)) // query the template input provider and make sure we generate
                    {
                        string propertyName = field.Name.AsNovelIdentifier(fieldKeys);
                        bool propertyAdded = CreateItemProperty(propertyName, field, concrete.Members);

                        if (propertyAdded)
                        {
                            // record usage of the property name
                            fieldKeys.Add(propertyName);
                        }
                    }
                }

                // generates interfaces to represent the Sitecore template inheritance hierarchy
                string baseInterface = GenerateInheritedInterfaces(template.Template, interfaceUnit, interfaceNamespace);
                if (!string.IsNullOrEmpty(baseInterface))
                    concrete.BaseTypes.Add(new CodeTypeReference(baseInterface, CodeTypeReferenceOptions.GlobalReference)); // implement the base type interface

                // create initializer class
                CreateInitializer(templateNamespace, concrete, template.Template.ID);
            }
        }
开发者ID:simonproctor,项目名称:Synthesis,代码行数:55,代码来源:Generator.cs


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