Drag-Drop-Set-Property-Item

This commit is contained in:
2023-07-03 15:53:10 -07:00
parent d23398db7a
commit 662ddfc44d
22 changed files with 652 additions and 77 deletions

View File

@ -1,3 +1,6 @@
using System.Drawing.Imaging;
using System.Reflection;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IProperty
@ -101,4 +104,14 @@ public interface IProperty
static List<DateTime> GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeFromName, DateTime? dateTimeOriginal, DateTime? gpsDateStamp) =>
Property.GetDateTimes(creationTime, lastWriteTime, dateTime, dateTimeDigitized, dateTimeFromName, dateTimeOriginal, gpsDateStamp);
byte[] TestStatic_GetBytes(string value) =>
GetBytes(value);
static byte[] GetBytes(string value) =>
Property.GetBytes(value);
PropertyItem TestStatic_GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
GetPropertyItem(constructorInfo, id, type, value);
static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
Property.GetPropertyItem(constructorInfo, id, type, value);
}

View File

@ -2,6 +2,7 @@ using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
@ -491,6 +492,30 @@ internal abstract class Property
return new(dateTimeOriginal, dateTimes, id, message);
}
internal static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value)
{
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
int length;
byte[] bytes;
if (type == 2)
{
bytes = GetBytes(value);
length = value.Length + 1;
}
else if (type == 1)
{
bytes = Encoding.Unicode.GetBytes($"{value}\0");
length = bytes.Length;
}
else
throw new NotSupportedException();
result.Id = id;
result.Len = length;
result.Type = type;
result.Value = bytes;
return result;
}
#pragma warning restore CA1416
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
@ -508,4 +533,13 @@ internal abstract class Property
return result;
}
internal static byte[] GetBytes(string value)
{
byte[] results = new byte[value.Length + 1];
for (int i = 0; i < value.Length; i++)
results[i] = (byte)value[i];
results[value.Length] = 0x00;
return results;
}
}