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


C# ProjectItem.ReadAllText方法代码示例

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


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

示例1: VerifyConfiguration

		public static bool VerifyConfiguration(ProjectItem projectItem)
		{
			var configProjectItem = SearchService.FindConfigFromModule(projectItem);
			if (configProjectItem == null)
			{
				throw new Exception($"Configuration file not found for module {projectItem.Name}");
			}
			string configText = configProjectItem.ReadAllText();

			var moduleText = projectItem.ReadAllText();
			var serviceNames =
				moduleText.Matches(@".GetObject\<(?<element>[^\>]+)\>")
					.Union(moduleText.Matches(@".GetRuntimeObject\<(?<element>[^\>]+)\>"))
					.Union(moduleText.Matches(@".RegisterInstance\<(?<element>[^\>]+)\>"));

			foreach (var serviceName in serviceNames)
			{
				var fullName = FindServiceFullName(serviceName);

				if (!configText.Contains(fullName))
				{
					throw new Exception($"{fullName} not found in the configuration file. Model: {projectItem.Name}");
				}
			}

			return false;
		}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:27,代码来源:ModuleClassService.cs

示例2: Execute

		public static void Execute(ProjectItem projectItem)
		{
			if (projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration") && !projectItem.ContainingProject.IsTestProject())
			{
				var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
				string configFile = projectItem.ReadAllText();

				var moduleConfig = configFile.Deserialize<XmlModuleConfig>();
				if (moduleConfig != null)
				{
					var project = dte.Solution.FindProject(p => p.Name == moduleConfig.AssemblyName);
					var moduleProjectItem = project.FindProjectItem(p => p.Name == moduleConfig.CsFileName);

					string csFile = moduleProjectItem.ReadAllText();

					string newConfig = DetermineNewConfig(configFile, csFile);

					if (!(configFile.EqualsExcludingWhitespace(newConfig)))
					{
						projectItem.Document?.Activate();
						projectItem.ClearAllText();
						projectItem.SetText(newConfig);
					}
				}
			}
		}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:26,代码来源:FactonizeModuleCommand.cs

示例3: GenerateConfig

		public static string GenerateConfig(ProjectItem module, ProjectItem config)
		{
			string moduleFileTxt = module.ReadAllText();
			string configFileTxt = config.ReadAllText();

			var requiredServices = GetReguiredServices(moduleFileTxt);
			var dependingServices = GetDependingServices(moduleFileTxt, configFileTxt);
			var providedServices = GetProvidedServices(moduleFileTxt);
			string classType = GetClassType(module);

			requiredServices = requiredServices.Where(s => dependingServices.All(d => d.ServiceName != s.ServiceName)).ToList();

			return GenerateConfigFileText(classType, requiredServices, dependingServices, providedServices);
		}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:14,代码来源:ModuleClassService.cs

示例4: Execute

		public static void Execute(ProjectItem projectItem)
		{
			SyntaxTree tree = CSharpSyntaxTree.ParseText(projectItem.ReadAllText());
			var root = (CompilationUnitSyntax)tree.GetRoot();

			var compilation = CSharpCompilation.Create("HelloWorld")
				.AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
				.AddSyntaxTrees(tree);
			var semanticModel = compilation.GetSemanticModel(tree);

			IEnumerable<MethodDeclarationSyntax> methods =
				root.DescendantNodes()					
					.OfType<MethodDeclarationSyntax>()
					.Where(m => m.DescendantTokens().All(x => x.Kind() != SyntaxKind.StaticKeyword))
					.ToList();

			foreach (var method in methods)
			{
				if (MethodShouldBeStatic(method, semanticModel))
				{
					var firstToken = method.GetFirstToken();
					var firstTokenTrivia = firstToken.LeadingTrivia;

					var formattedMethodDeclaration = method.ReplaceToken(firstToken, firstToken.WithLeadingTrivia(SyntaxFactory.TriviaList()));

					SyntaxTriviaList syntaxTriviaList = firstTokenTrivia.ToSyntaxTriviaList();
					var staticToken = SyntaxFactory.Token(syntaxTriviaList, SyntaxKind.StaticKeyword, new SyntaxTriviaList());

					var newModifiers = SyntaxFactory.TokenList(new[] { staticToken }.Concat(formattedMethodDeclaration.Modifiers));

					var newMethodDeclaration = formattedMethodDeclaration.Update(
						formattedMethodDeclaration.AttributeLists,
						newModifiers,
						formattedMethodDeclaration.ReturnType,
						formattedMethodDeclaration.ExplicitInterfaceSpecifier,
						formattedMethodDeclaration.Identifier,
						formattedMethodDeclaration.TypeParameterList,
						formattedMethodDeclaration.ParameterList,
						formattedMethodDeclaration.ConstraintClauses,
						formattedMethodDeclaration.Body,
						formattedMethodDeclaration.SemicolonToken);

					var formattedLocalDeclaration = CodeActionAnnotations.FormattingAnnotation.AddAnnotationTo(newMethodDeclaration);

					var newRoot = root.ReplaceNode(method, formattedLocalDeclaration);
					return _editFactory.CreateTreeTransformEdit(_document.Project.Solution,
						tree, newRoot, cancellationToken: cancellationToken);
				}
				
			}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:50,代码来源:MakeStaticMethodsCommand.cs

示例5: Execute

		public static void Execute(ProjectItem projectItem)
		{
			string textToInsert = string.Format(Text, projectItem.Name);			

			var objTextDoc = (TextDocument)projectItem.Document.Object("TextDocument");
			EditPoint editPoint = objTextDoc.StartPoint.CreateEditPoint();
			while (string.IsNullOrWhiteSpace(editPoint.GetLineText()))
			{
				editPoint.DeleteCurrentLine();				
			}
		
			if (projectItem.ReadAllText().TrimStart().StartsWith(textToInsert, StringComparison.InvariantCulture))
			{
				return;
			}

			var txtSel = (TextSelection)projectItem.Document.Selection;
			txtSel.MoveTo(0, 0);

			TextRanges ranges = null;
			int findOptions = (int)(vsFindOptions.vsFindOptionsRegularExpression | vsFindOptions.vsFindOptionsFromStart);
			if (txtSel.FindPattern(RegExText, findOptions, ref ranges))
			{
				var firstRange = ranges.OfType<TextRange>().FirstOrDefault();
				if (firstRange != null)
				{
					var rangeText = firstRange.StartPoint.GetText(firstRange.EndPoint);
					if (rangeText.Trim().Equals(textToInsert.Trim(), StringComparison.InvariantCulture))
					{
						return;
					}
					firstRange.StartPoint.Delete(firstRange.EndPoint);
				}
			}

			txtSel.GotoLine(1, true);
			txtSel.StartOfLine();
			txtSel.NewLine();
			txtSel.GotoLine(1, true);
			txtSel.Insert(textToInsert);
		}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:41,代码来源:AddCopyrightCommand.cs


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