本文整理汇总了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;
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
}
示例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);
}