mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Added net35, net40, net6.0 TFMs to Credentials
This commit is contained in:
@@ -133,12 +133,24 @@ namespace Meziantou.Framework.Win32
|
||||
}
|
||||
}
|
||||
|
||||
public static IReadOnlyList<Credential> EnumerateCrendentials()
|
||||
public static
|
||||
#if NETSTANDARD1_0_OR_GREATER
|
||||
IReadOnlyList<Credential>
|
||||
#else
|
||||
IList<Credential>
|
||||
#endif
|
||||
EnumerateCrendentials()
|
||||
{
|
||||
return EnumerateCrendentials(null);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<Credential> EnumerateCrendentials(string filter)
|
||||
public static
|
||||
#if NETSTANDARD1_0_OR_GREATER
|
||||
IReadOnlyList<Credential>
|
||||
#else
|
||||
IList<Credential>
|
||||
#endif
|
||||
EnumerateCrendentials(string filter)
|
||||
{
|
||||
var result = new List<Credential>();
|
||||
var ret = Advapi32.CredEnumerate(filter, 0, out var count, out var pCredentials);
|
||||
@@ -148,8 +160,8 @@ namespace Meziantou.Framework.Win32
|
||||
{
|
||||
for (var n = 0; n < count; n++)
|
||||
{
|
||||
var credential = Marshal.ReadIntPtr(pCredentials, n * Marshal.SizeOf<IntPtr>());
|
||||
result.Add(ReadCredential(Marshal.PtrToStructure<CREDENTIAL>(credential)));
|
||||
var credential = Marshal.ReadIntPtr(pCredentials, n * MarshalEx.SizeOf<IntPtr>());
|
||||
result.Add(ReadCredential(MarshalEx.PtrToStructure<CREDENTIAL>(credential)));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -14,9 +14,7 @@ namespace Meziantou.Framework.Win32
|
||||
public CREDENTIAL GetCredential()
|
||||
{
|
||||
if (!IsInvalid)
|
||||
{
|
||||
return Marshal.PtrToStructure<CREDENTIAL>(handle);
|
||||
}
|
||||
return MarshalEx.PtrToStructure<CREDENTIAL>(handle);
|
||||
|
||||
throw new InvalidOperationException("Invalid CriticalHandle!");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace System.Runtime.InteropServices
|
||||
{
|
||||
internal static class MarshalEx
|
||||
{
|
||||
public static int SizeOf<T>()
|
||||
{
|
||||
#if NETSTANDARD1_0_OR_GREATER
|
||||
return Marshal.SizeOf<T>();
|
||||
#else
|
||||
return Marshal.SizeOf(typeof(T));
|
||||
#endif
|
||||
}
|
||||
|
||||
public static T PtrToStructure<T>(IntPtr ptr)
|
||||
{
|
||||
#if NETSTANDARD1_0_OR_GREATER
|
||||
return Marshal.PtrToStructure<T>(ptr);
|
||||
#else
|
||||
return (T)Marshal.PtrToStructure(ptr, typeof(T));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,11 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks>netstandard2.0;net35;net40;net461;net6.0</TargetFrameworks>
|
||||
<Description>C# wrapper around CredWrite/CredRead/CredDelete functions to store and retrieve from Windows Credential Store</Description>
|
||||
<RootNamespace>Meziantou.Framework.Win32</RootNamespace>
|
||||
<Version>1.1.1</Version>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net461' ">
|
||||
<DefineConstants>$(DefineConstants);NETSTANDARD1_0_OR_GREATER;NETSTANDARD2_0_OR_GREATER</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user