當前位置: 首頁>>代碼示例>>C#>>正文


C# CodeClass類代碼示例

本文整理匯總了C#中CodeClass的典型用法代碼示例。如果您正苦於以下問題:C# CodeClass類的具體用法?C# CodeClass怎麽用?C# CodeClass使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CodeClass類屬於命名空間,在下文中一共展示了CodeClass類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddProperty

        /// <summary>
        /// Adds the property.
        /// </summary>
        /// <param name="codeClass">The code class.</param>
        /// <param name="var">The var.</param>
        /// <returns></returns>
        public static CodeProperty AddProperty(CodeClass codeClass, CodeVariable var)
        {
            CodeProperty prop = null;

            try
            {
                prop = codeClass.AddProperty(
                    FormatPropertyName(var.Name),
                    FormatPropertyName(var.Name),
                    var.Type.AsFullName, -1,
                    vsCMAccess.vsCMAccessPublic, null);

                EditPoint editPoint = prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                //Delete return default(int); added by codeClass.AddProperty
                editPoint.Delete(editPoint.LineLength);

                editPoint.Indent(null, 4);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "return {0};", var.Name));

                editPoint = prop.Setter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                editPoint.Indent(null, 1);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "{0} = value;", var.Name));
                editPoint.SmartFormat(editPoint);

                return prop;
            }
            catch
            {
                //Property already exists
                return null;
            }
        }
開發者ID:riseandcode,項目名稱:open-wscf-2010,代碼行數:40,代碼來源:FileCodeModelHelper.cs

示例2: VisitClass

 protected override void VisitClass(CodeClass codeClass)
 {
     if (codeClass.FullName == _classFullName)
     {
         _result = codeClass.ProjectItem;
     }
 }
開發者ID:569550384,項目名稱:Rafy,代碼行數:7,代碼來源:TypeFileFinder.cs

示例3: HaveAClass

 // Methods
 public static bool HaveAClass(object target, out CodeClass codeClass)
 {
     ProjectItem projectItem = null;
     if (target is SelectedItems)
     {
         SelectedItems items = (SelectedItems)target;
         if ((items.Count > 1) && (items.Item(1).ProjectItem != null))
         {
             projectItem = items.Item(1).ProjectItem;
         }
     }
     else if (target is ProjectItem)
     {
         projectItem = (ProjectItem)target;
     }
     if ((projectItem != null) && (projectItem.FileCodeModel != null))
     {
         foreach (CodeElement element in projectItem.FileCodeModel.CodeElements)
         {
             if (element is CodeNamespace)
             {
                 CodeNamespace namespace2 = (CodeNamespace)element;
                 if ((namespace2.Members.Count > 0) && (namespace2.Members.Item(1) is CodeClass))
                 {
                     codeClass = (CodeClass)namespace2.Members.Item(1);
                     return true;
                 }
             }
         }
     }
     codeClass = null;
     return false;
 }
開發者ID:Phidiax,項目名稱:open-wssf-2015,代碼行數:34,代碼來源:ReferenceUtil.cs

示例4: GetClassDeclaration

        /// <summary>
        /// Gets the declaration of the specified code class as a string.
        /// </summary>
        /// <param name="codeClass">The code class.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetClassDeclaration(CodeClass codeClass)
        {
            // Get the start point after the attributes.
            var startPoint = codeClass.GetStartPoint(vsCMPart.vsCMPartHeader);

            return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{");
        }
開發者ID:reima,項目名稱:codemaid,代碼行數:12,代碼來源:CodeElementHelper.cs

示例5: AddAttribute

 /// <summary>
 /// Adds the attribute.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="attributeName">Name of the attribute.</param>
 /// <param name="attributeValue">The attribute value.</param>
 public static void AddAttribute(CodeClass element, string attributeName, string attributeValue)
 {
     if(!HasAttribute(element, attributeName))
     {
         element.AddAttribute(attributeName, attributeValue, 0);
     }
 }
開發者ID:riseandcode,項目名稱:open-wscf-2010,代碼行數:13,代碼來源:FileCodeModelHelper.cs

示例6: CanGenerateHandleCodeProperty

      internal static bool CanGenerateHandleCodeProperty(string testClassFixturePostFix, CodeClass parentCodeClass, CodeProperty codeProperty, Project unitTestProject)
      {
         foreach (ProjectItem projectItem in unitTestProject.ProjectItems)
         {
            List<CodeClass> lstProjectCodeClasses = UTGManagerAndExaminor.ProjectItemExaminor.GetCodeClasses(projectItem.FileCodeModel);

            foreach (CodeClass codeClass in lstProjectCodeClasses)
            {
               if ((parentCodeClass.Name + testClassFixturePostFix).Equals(codeClass.Name))
               {
                  foreach (CodeElement codeElement in codeClass.Members)
                  {
                     if (codeElement is CodeProperty)
                     {
                        if (codeProperty.Name.Equals(((CodeProperty)codeElement).Name))
                           return false;

                     }
                  }
               }
            }
         }

         return true;
      }
開發者ID:codemonkies,項目名稱:UTGV1.0,代碼行數:25,代碼來源:CodeSelectionHandler.cs

示例7: ParseDomainNamespace

        /// <summary>
        /// 解析出實體的命令空間。
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        private static bool ParseDomainNamespace(CodeClass repo, string entityName, IList<CodeClass> entities, out string domainNamespace)
        {
            domainNamespace = null;

            //如果實體和倉庫都是在這同一個項目中時,直接在實體列表中找到對應實體的命令空間。
            if (entities.Count > 0)
            {
                var entity = entities.FirstOrDefault(c => c.Name == entityName);
                if (entity != null)
                {
                    domainNamespace = entity.Namespace.FullName;
                    return true;
                }
            }

            //實體不在同一個項目中,則通過約定查找實體的命名空間:
            //Repository.g.cs 文件中的最後一個命名空間,即是實體的命名空間。
            var item = repo.ProjectItem;
            var fileName = item.get_FileNames(1);
            var gFileName = Path.GetFileNameWithoutExtension(fileName) + ".g.cs";
            var gFile = Path.Combine(Path.GetDirectoryName(fileName), gFileName);

            //Repository 的層基類是沒有 .g.cs 文件的,這時不需要為它生成。
            if (File.Exists(gFile))
            {
                var code = File.ReadAllText(gFile);
                var match = Regex.Match(code, @"using (?<domainNamespace>\S+?);\s+namespace");
                domainNamespace = match.Groups["domainNamespace"].Value;
                return !string.IsNullOrWhiteSpace(domainNamespace);
            }
            return false;
        }
開發者ID:569550384,項目名稱:Rafy,代碼行數:37,代碼來源:RefreshAutoCodeCommand.cs

示例8: ProcessCodeFunctions

 private void ProcessCodeFunctions(CodeClass codeClass, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     foreach (var codeFunction in codeClass.Children.OfType<CodeFunction>())
     {
         var bindingSourceMethod = CreateBindingSourceMethod(codeFunction, bindingSourceType, bindingSourceProcessor);
         if (bindingSourceMethod != null)
             bindingSourceProcessor.ProcessMethod(bindingSourceMethod);
     }
 }
開發者ID:Galad,項目名稱:SpecFlow,代碼行數:9,代碼來源:VsBindingRegistryBuilder.cs

示例9: VisitClass

        protected override void VisitClass(CodeClass codeClass)
        {
            this.ShowName(codeClass, "Class");

            _level++;

            base.VisitClass(codeClass);

            _level--;
        }
開發者ID:569550384,項目名稱:Rafy,代碼行數:10,代碼來源:TextVisitor.cs

示例10: IsBindingClass

 static public bool IsBindingClass(CodeClass codeClass)
 {
     try
     {
         return codeClass.Attributes.Cast<CodeAttribute>().Any(attr => typeof(BindingAttribute).FullName.Equals(attr.FullName));
     }
     catch(Exception)
     {
         return false;
     }
 }
開發者ID:roffster,項目名稱:SpecFlow,代碼行數:11,代碼來源:VsStepSuggestionBindingCollector.cs

示例11: IsBindingClass

 static public bool IsBindingClass(CodeClass codeClass)
 {
     try
     {
         return codeClass.Attributes.Cast<CodeAttribute>().Any(attr => "TechTalk.SpecFlow.BindingAttribute".Equals(attr.FullName));
     }
     catch(Exception)
     {
         return false;
     }
 }
開發者ID:hedaayat,項目名稱:SpecFlow,代碼行數:11,代碼來源:VsStepSuggestionBindingCollector.cs

示例12: ClassTraverser

        public ClassTraverser(CodeClass codeClass, Action<CodeProperty> withProperty)
        {
            if (codeClass == null) throw new ArgumentNullException("codeClass");
            if (withProperty == null) throw new ArgumentNullException("withProperty");

            CodeClass = codeClass;
            WithProperty = withProperty;

            if (codeClass.Members != null)
                Traverse(codeClass.Members);
        }
開發者ID:dolly22,項目名稱:t4ts,代碼行數:11,代碼來源:ClassTraverser.cs

示例13: IsPotentialBindingClass

 static internal bool IsPotentialBindingClass(CodeClass codeClass)
 {
     try
     {
         var filteredAttributes = codeClass.Attributes.OfType<CodeAttribute2>();
         return BindingSourceProcessor.IsPotentialBindingClass(filteredAttributes.Select(attr => attr.FullName));
     }
     catch(Exception)
     {
         return false;
     }
 }
開發者ID:grassynoel,項目名稱:SpecFlow,代碼行數:12,代碼來源:VsBindingRegistryBuilder.cs

示例14: VisitClass

 protected override void VisitClass(CodeClass codeClass)
 {
     if (Helper.IsEntity(codeClass))
     {
         _fileFinised = true;
     }
     else if (Helper.IsRepository(codeClass))
     {
         _result.Add(codeClass);
         _fileFinised = true;
     }
 }
開發者ID:569550384,項目名稱:Rafy,代碼行數:12,代碼來源:RepoFileFinder.cs

示例15: DerivedFromBaseTest

        private static bool DerivedFromBaseTest(CodeClass classElement)
        {
            if (classElement.Name == "BaseTest")
            {
                return true;
            }

            return classElement.Bases
                       .Cast<CodeElement>()
                       .Where(e => e.Kind == vsCMElement.vsCMElementClass)
                       .Count(c => DerivedFromBaseTest((CodeClass)c)) > 0;
        }
開發者ID:MonsterCoder,項目名稱:MavenThought.VSExtension,代碼行數:12,代碼來源:ClassItemFactory.VSExtensionPackage.cs


注:本文中的CodeClass類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。