Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Improve SC-style import commands around types for which we use workar…
…ounds for import
- Loading branch information
Showing
8 changed files
with
346 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Rubberduck.VBEEditor/Utility/ModuleNameFromFileExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Rubberduck.VBEditor.Extensions; | ||
|
||
namespace Rubberduck.VBEditor.Utility | ||
{ | ||
public interface IModuleNameFromFileExtractor | ||
{ | ||
string ModuleName(string filename); | ||
} | ||
|
||
public class ModuleNameFromFileExtractor : IModuleNameFromFileExtractor | ||
{ | ||
public string ModuleName(string filename) | ||
{ | ||
if (!File.Exists(filename)) | ||
{ | ||
return null; | ||
} | ||
|
||
//We cannot read binary files. | ||
if(ComponentTypeExtensions.FormBinaryExtension.Equals(Path.GetExtension(filename))) | ||
{ | ||
return Path.GetFileNameWithoutExtension(filename); | ||
} | ||
|
||
var contents = File.ReadLines(filename, Encoding.Default); | ||
var nameLine = contents.FirstOrDefault(line => line.StartsWith("Attribute VB_Name = ")); | ||
if (nameLine == null) | ||
{ | ||
return Path.GetFileNameWithoutExtension(filename); | ||
} | ||
|
||
//The format is Attribute VB_Name = "ModuleName" | ||
return nameLine.Substring("Attribute VB_Name = ".Length + 1, nameLine.Length - "Attribute VB_Name = ".Length - 2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.