-
Notifications
You must be signed in to change notification settings - Fork 889
/
Signature.cs
78 lines (68 loc) · 2.3 KB
/
Signature.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Runtime.InteropServices;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
/// <summary>
/// A signature
/// </summary>
public class Signature
{
private readonly DateTimeOffset when;
private readonly string name;
private readonly string email;
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
internal Signature(IntPtr signaturePtr)
{
var handle = new GitSignature();
Marshal.PtrToStructure(signaturePtr, handle);
// XXX: This is unbelievably hacky, but I can't get the
// Utf8Marshaller to work properly.
name = (string)marshaler.MarshalNativeToManaged(handle.Name);
email = (string)marshaler.MarshalNativeToManaged(handle.Email);
when = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset);
}
/// <summary>
/// Initializes a new instance of the <see cref = "Signature" /> class.
/// </summary>
/// <param name = "name">The name.</param>
/// <param name = "email">The email.</param>
/// <param name = "when">The when.</param>
public Signature(string name, string email, DateTimeOffset when)
{
this.name = name;
this.email = email;
this.when = when;
}
internal SignatureSafeHandle BuildHandle()
{
SignatureSafeHandle signature;
int result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(),
(int) when.Offset.TotalMinutes);
Ensure.Success(result);
return signature;
}
/// <summary>
/// Gets the name.
/// </summary>
public string Name
{
get { return name; }
}
/// <summary>
/// Gets the email.
/// </summary>
public string Email
{
get { return email; }
}
/// <summary>
/// Gets the date when this signature happened.
/// </summary>
public DateTimeOffset When
{
get { return when; }
}
}
}