, . API VBIDE , , .
API VBIDE - .
Rubberduck (, , ..), , , .
", , ", , . , :
Option Explicit
Sub DoSomething
'todo: implement
End Sub
:
Option Explicit
Sub DoSomething
DoSomethingElse 42
End Sub
, , , . , .
, CodeModule, hash it, - - , "" . #, , COM, VBA, DLL .NET, COM- , String , .
Rubberduck.VBEditor.SafeComWrappers.VBA.CodeModule, :
private string _previousContentHash;
public string ContentHash()
{
using (var hash = new SHA256Managed())
using (var stream = Content().ToStream())
{
return _previousContentHash = new string(Encoding.Unicode.GetChars(hash.ComputeHash(stream)));
}
}
public string Content()
{
return Target.CountOfLines == 0 ? string.Empty : GetLines(1, CountOfLines);
}
public string GetLines(Selection selection)
{
return GetLines(selection.StartLine, selection.LineCount);
}
public string GetLines(int startLine, int count)
{
return Target.get_Lines(startLine, count);
}
Target - Microsoft.Vbe.Interop.CodeModule - VBA, a CodeModule, VBA; - :
Public Function IsModified(ByVal target As CodeModule, ByVal previousHash As String) As Boolean
Dim content As String
If target.CountOfLines = 0 Then
content = vbNullString
Else
content = target.GetLines(1, target.CountOfLines)
End If
Dim hash As String
hash = MyHashingLibrary.MyHashingFunction(content)
IsModified = (hash <> previousHash)
End Function
, "" - . :
- " " , , , .
ObjPtr , , , VBA, , COM- - COM- - . , 100% VBA.
Dictionary, , .
Rubberduck, , (.. ) VBE =)
