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


C# XName.Contains方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XName.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# XName.Contains方法的具體用法?C# XName.Contains怎麽用?C# XName.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XName的用法示例。


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

示例1: Execute

        public override void Execute() {
            if(Pause) {
                Console.WriteLine("Ready to begin (press Enter)");
                Console.ReadLine();
            }

            Console.WriteLine("Using srcML file {0}", this.File);

            var builder = new UnigramSwumBuilder();
            if(!string.IsNullOrWhiteSpace(CountFile)) {
                Console.WriteLine("Initializing SamuraiIdSplitter using word count file {0}", this.CountFile);
                builder.Splitter = new SamuraiIdSplitter(CountFile);
            }
            Console.WriteLine("SwumBuilder initialized");

            int methodCount = 0, fieldCount = 0;

            {
                SrcMLFile testFile = new SrcMLFile(this.File);
                var functionTypes = new XName[] {SRC.Function, SRC.Constructor, SRC.Destructor};
                foreach(XElement file in testFile.FileUnits) {
                    string fileName = file.Attribute("filename").Value;
                    Console.WriteLine("File {0}:", fileName);

                    //compute SWUM on each function
                    foreach(var func in (from func in file.Descendants()
                                         where functionTypes.Contains(func.Name) && !func.Ancestors(SRC.Declaration).Any()
                                         select func)) {
                        var nameElement = SrcMLElement.GetNameForMethod(func);
                        if(nameElement != null) {
                            string funcName = nameElement.Value;
                            string funcSignature = SrcMLElement.GetMethodSignature(func);
                            if(PrintSwum) {
                                Console.WriteLine("<{0}> {1}", func.Name.LocalName, funcSignature);
                            }

                            MethodDeclarationNode mdn = new MethodDeclarationNode(funcName, ContextBuilder.BuildMethodContext(func));
                            builder.ApplyRules(mdn);
                            methodSwum[string.Format("{0}:{1}", fileName, funcSignature)] = mdn;
                            if(PrintSwum) {
                                Console.WriteLine(mdn.ToString() + Environment.NewLine);
                            }

                            methodCount++;
                        }
                    }

                    //compute SWUM on each field
                    foreach(var fieldDecl in (from declStmt in file.Descendants(SRC.DeclarationStatement)
                                          where !declStmt.Ancestors().Any(n => functionTypes.Contains(n.Name))
                                          select declStmt.Element(SRC.Declaration))) {

                        int declPos = 1;
                        foreach(var nameElement in fieldDecl.Elements(SRC.Name)) {

                            string fieldName = nameElement.Elements(SRC.Name).Any() ? nameElement.Elements(SRC.Name).Last().Value : nameElement.Value;
                            if(PrintSwum) {
                                Console.WriteLine("Field: {0}, Name: {1}", fieldDecl.Value, fieldName);
                            }

                            FieldDeclarationNode fdn = new FieldDeclarationNode(fieldName, ContextBuilder.BuildFieldContext(fieldDecl));
                            builder.ApplyRules(fdn);
                            fieldSwum[string.Format("{0}:{1}:{2}", fileName, fieldDecl.Value, declPos)] = fdn;
                            if(PrintSwum) {
                                Console.WriteLine(fdn.ToString() + Environment.NewLine);
                            }

                            fieldCount++;
                            declPos++;
                        }
                    }
                }
                
            } 

            GC.Collect();

            Console.WriteLine("{0} functions analyzed", methodCount);
            Console.WriteLine("{0} functions in dictionary", methodSwum.Count);
            Console.WriteLine("{0} fields analyzed", fieldCount);
            Console.WriteLine("{0} fields in dictionary", fieldSwum.Count);

            if(Pause) {
                Console.WriteLine("Finished building SWUM (press Enter)");
                Console.ReadLine();
            }
        }
開發者ID:abb-iss,項目名稱:Swum.NET,代碼行數:87,代碼來源:Program.cs


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