Skip to content

Commit

Permalink
+ISlnContainer.SetDefaultHandlers - SlnParser now can be initialized …
Browse files Browse the repository at this point in the history
…without handlers at all.

```
  ISlnContainer sln = new SlnParser(false);
  sln.SlnHandlers.Register(new LMySpec());
  ...

  // to reset and register all default:
  sln.SetDefaultHandlers();
```

also fixed MapTest1 because of new handler from 3b98b5e
  • Loading branch information
3F committed Sep 26, 2017
1 parent 3b98b5e commit 0f0aed5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions MvsSln/Core/ISlnContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public interface ISlnContainer
/// </summary>
IDictionary<string, RawText> RawXmlProjects { get; set; }

/// <summary>
/// To reset and register all default handlers.
/// </summary>
void SetDefaultHandlers();

/// <summary>
/// Parse of selected .sln file.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions MvsSln/Core/SlnHandlers/LVisualStudioVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public override bool Positioned(ISvc svc, RawText line)
return false;
}

LSender.Send(this, $"Found version from header: '{lineType}' = '{version}'", Message.Level.Info);

var h = new SlnHeader(svc.Sln.Header);
switch(lineType)
{
Expand Down
31 changes: 22 additions & 9 deletions MvsSln/Core/SlnParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ public IDictionary<string, RawText> RawXmlProjects
set;
}

/// <summary>
/// To reset and register all default handlers.
/// </summary>
public void SetDefaultHandlers()
{
SlnHandlers.Reset();

SlnHandlers.Register(new LVisualStudioVersion());
SlnHandlers.Register(new LProject());
SlnHandlers.Register(new LProjectDependencies());
SlnHandlers.Register(new LProjectSolutionItems());
SlnHandlers.Register(new LProjectConfigurationPlatforms());
SlnHandlers.Register(new LSolutionConfigurationPlatforms());

// TODO: validate CoHandlers ref
}

/// <summary>
/// Parse of selected .sln file.
/// </summary>
Expand Down Expand Up @@ -137,16 +154,12 @@ public ISlnResult Parse(StreamReader reader, SlnItems type)
return data;
}

public SlnParser()
/// <param name="defaultHandlers">To register and activate all handlers by default if true.</param>
public SlnParser(bool defaultHandlers = true)
{
SlnHandlers.Register(new LVisualStudioVersion());
SlnHandlers.Register(new LProject());
SlnHandlers.Register(new LProjectDependencies());
SlnHandlers.Register(new LProjectSolutionItems());
SlnHandlers.Register(new LProjectConfigurationPlatforms());
SlnHandlers.Register(new LSolutionConfigurationPlatforms());

// TODO: validate CoHandlers ref
if(defaultHandlers) {
SetDefaultHandlers();
}
}

protected void Process(ISvc svc)
Expand Down
2 changes: 1 addition & 1 deletion MvsSlnTest/SlnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void MapTest1()
var map = sln.Result.Map;
Assert.AreEqual(38, map.Count);

Assert.AreEqual(null, map[0].Handler);
Assert.AreEqual(typeof(LVisualStudioVersion), map[0].Handler.GetType());

Assert.AreEqual(typeof(LProject), map[1].Handler.GetType());
Assert.AreEqual(typeof(LProjectDependencies), map[2].Handler.GetType());
Expand Down

0 comments on commit 0f0aed5

Please sign in to comment.