diff options
author | Tim Clem <timothy.clem@gmail.com> | 2011-03-28 21:22:36 +0400 |
---|---|---|
committer | Tim Clem <timothy.clem@gmail.com> | 2011-03-30 20:30:59 +0400 |
commit | b6da353cd6d8de20427bc0218e33b4dd7add705a (patch) | |
tree | d24eb8ade2a1d7454e1442b5cc18d0bc90a76484 /LibGit2Sharp/Signature.cs | |
parent | 88c98c0f1f01b65c40d86fa044c9fd7e258b4402 (diff) |
add back in basic object lookup with new interop
New Lookup API includes:
TryLookup
TryLookup<T>
Lookup
Lookup<T>
Looks like VS2010 can deal with optional params for .net 3.5 projects,
so NET35 ifdefs not necessary yet.
Diffstat (limited to 'LibGit2Sharp/Signature.cs')
-rw-r--r-- | LibGit2Sharp/Signature.cs | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/LibGit2Sharp/Signature.cs b/LibGit2Sharp/Signature.cs index 0ec61a8d..c72bfb18 100644 --- a/LibGit2Sharp/Signature.cs +++ b/LibGit2Sharp/Signature.cs @@ -1,53 +1,73 @@ -/* - * The MIT License - * - * Copyright (c) 2011 LibGit2Sharp committers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +#region Copyright (c) 2011 LibGit2Sharp committers + +// The MIT License +// +// Copyright (c) 2011 LibGit2Sharp committers +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#endregion using System; +using System.Runtime.InteropServices; namespace LibGit2Sharp { public class Signature { + private readonly GitSignature sig = new GitSignature(); + private DateTimeOffset? when; + + internal Signature(IntPtr signaturePtr, bool ownedByRepo = true) + { + Marshal.PtrToStructure(signaturePtr, sig); + if (!ownedByRepo) + { + NativeMethods.git_signature_free(signaturePtr); + } + } + public Signature(string name, string email, DateTimeOffset when) + : this(NativeMethods.git_signature_new(name, email, when.ToSecondsSinceEpoch(), (int) when.Offset.TotalMinutes), false) + { + } + + public string Name { - Name = name; - Email = email; - When = when; + get { return sig.Name; } } - /// <summary> - /// Full name - /// </summary> - public string Name { get; private set; } - - /// <summary> - /// Email address - /// </summary> - public string Email { get; private set; } - - /// <summary> - /// Time when this person committed the change - /// </summary> - public DateTimeOffset When { get; private set; } + public string Email + { + get { return sig.Email; } + } + + public DateTimeOffset When + { + get + { + if (when == null) + { + when = Epoch.ToDateTimeOffset(sig.When.Time, sig.When.Offset); + } + return when.Value; + } + } } -} +}
\ No newline at end of file |