mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Playing with nullable.
This commit is contained in:
parent
64e631bd2a
commit
299e74621b
@ -19,9 +19,9 @@
|
||||
|
||||
<Version>$(PkgVersion)</Version>
|
||||
<FileVersion>$(PkgVersion)</FileVersion>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<!--don't warn missing xml docs and naming conventions-->
|
||||
<NoWarn>1591,IDE1006</NoWarn>
|
||||
<LangVersion>11</LangVersion>
|
||||
<!--don't warn missing xml docs, naming conventions, and suppressions-->
|
||||
<NoWarn>1591,IDE1006,IDE0079</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
|
@ -3,10 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||
<TargetFrameworks>net462;netcoreapp3.1;net5.0;net6.0;net7.0;netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks>net462;net6.0;net7.0;netstandard2.0</TargetFrameworks>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>11</LangVersion>
|
||||
</PropertyGroup>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
|
@ -139,89 +139,89 @@ namespace TWAINWorkingGroup
|
||||
public string ResponseJson;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A more dotnet-friendly representation of <see cref="TW_ENUMERATION"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
public class Enumeration<TValue> where TValue : struct
|
||||
{
|
||||
public int CurrentIndex;
|
||||
///// <summary>
|
||||
///// A more dotnet-friendly representation of <see cref="TW_ENUMERATION"/>.
|
||||
///// </summary>
|
||||
///// <typeparam name="TValue"></typeparam>
|
||||
//public class Enumeration<TValue> where TValue : struct
|
||||
//{
|
||||
// public int CurrentIndex;
|
||||
|
||||
public int DefaultIndex;
|
||||
// public int DefaultIndex;
|
||||
|
||||
public TValue[] Items;
|
||||
}
|
||||
// public TValue[] Items;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// A more dotnet-friendly representation of <see cref="TW_RANGE"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
public partial class Range<TValue> : IEnumerable<TValue> where TValue : struct
|
||||
{
|
||||
public TValue MinValue;
|
||||
public TValue MaxValue;
|
||||
public TValue StepSize;
|
||||
public TValue DefaultValue;
|
||||
public TValue CurrentValue;
|
||||
///// <summary>
|
||||
///// A more dotnet-friendly representation of <see cref="TW_RANGE"/>.
|
||||
///// </summary>
|
||||
///// <typeparam name="TValue"></typeparam>
|
||||
//public partial class Range<TValue> : IEnumerable<TValue> where TValue : struct
|
||||
//{
|
||||
// public TValue MinValue;
|
||||
// public TValue MaxValue;
|
||||
// public TValue StepSize;
|
||||
// public TValue DefaultValue;
|
||||
// public TValue CurrentValue;
|
||||
|
||||
IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator()
|
||||
{
|
||||
if (!(MinValue is IConvertible))
|
||||
throw new NotSupportedException($"The value type {typeof(TValue).Name} is not supported for range enumeration.");
|
||||
// IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator()
|
||||
// {
|
||||
// if (!(MinValue is IConvertible))
|
||||
// throw new NotSupportedException($"The value type {typeof(TValue).Name} is not supported for range enumeration.");
|
||||
|
||||
return new DynamicEnumerator(MinValue, MaxValue, StepSize);
|
||||
}
|
||||
// return new DynamicEnumerator(MinValue, MaxValue, StepSize);
|
||||
// }
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<TValue>)this).GetEnumerator();
|
||||
}
|
||||
// IEnumerator IEnumerable.GetEnumerator()
|
||||
// {
|
||||
// return ((IEnumerable<TValue>)this).GetEnumerator();
|
||||
// }
|
||||
|
||||
// dynamic is a cheap hack to sidestep the compiler restrictions if I know TValue is numeric
|
||||
class DynamicEnumerator : IEnumerator<TValue>
|
||||
{
|
||||
private readonly TValue _min;
|
||||
private readonly TValue _max;
|
||||
private readonly TValue _step;
|
||||
private TValue _cur;
|
||||
bool started = false;
|
||||
// // dynamic is a cheap hack to sidestep the compiler restrictions if I know TValue is numeric
|
||||
// class DynamicEnumerator : IEnumerator<TValue>
|
||||
// {
|
||||
// private readonly TValue _min;
|
||||
// private readonly TValue _max;
|
||||
// private readonly TValue _step;
|
||||
// private TValue _cur;
|
||||
// bool started = false;
|
||||
|
||||
public DynamicEnumerator(TValue min, TValue max, TValue step)
|
||||
{
|
||||
_min = min;
|
||||
_max = max;
|
||||
_step = step;
|
||||
_cur = min;
|
||||
}
|
||||
// public DynamicEnumerator(TValue min, TValue max, TValue step)
|
||||
// {
|
||||
// _min = min;
|
||||
// _max = max;
|
||||
// _step = step;
|
||||
// _cur = min;
|
||||
// }
|
||||
|
||||
public TValue Current => _cur;
|
||||
// public TValue Current => _cur;
|
||||
|
||||
object IEnumerator.Current => this.Current;
|
||||
// object IEnumerator.Current => this.Current;
|
||||
|
||||
public void Dispose() { }
|
||||
// public void Dispose() { }
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
started = true;
|
||||
return true;
|
||||
}
|
||||
// public bool MoveNext()
|
||||
// {
|
||||
// if (!started)
|
||||
// {
|
||||
// started = true;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
var next = _cur + (dynamic)_step;
|
||||
if (next == _cur || next < _min || next > _max) return false;
|
||||
// var next = _cur + (dynamic)_step;
|
||||
// if (next == _cur || next < _min || next > _max) return false;
|
||||
|
||||
_cur = next;
|
||||
return true;
|
||||
}
|
||||
// _cur = next;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_cur = _min;
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// public void Reset()
|
||||
// {
|
||||
// _cur = _min;
|
||||
// started = false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
partial struct TW_FIX32 : IEquatable<TW_FIX32>, IConvertible
|
||||
{
|
||||
@ -262,7 +262,7 @@ namespace TWAINWorkingGroup
|
||||
{
|
||||
return Whole == other.Whole && Frac == other.Frac;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is TW_FIX32 other)
|
||||
{
|
||||
@ -283,82 +283,82 @@ namespace TWAINWorkingGroup
|
||||
return TypeCode.Single;
|
||||
}
|
||||
|
||||
bool IConvertible.ToBoolean(IFormatProvider provider)
|
||||
bool IConvertible.ToBoolean(IFormatProvider? provider)
|
||||
{
|
||||
return this != 0;
|
||||
}
|
||||
|
||||
byte IConvertible.ToByte(IFormatProvider provider)
|
||||
byte IConvertible.ToByte(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToByte((float)this);
|
||||
}
|
||||
|
||||
char IConvertible.ToChar(IFormatProvider provider)
|
||||
char IConvertible.ToChar(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToChar((float)this);
|
||||
}
|
||||
|
||||
DateTime IConvertible.ToDateTime(IFormatProvider provider)
|
||||
DateTime IConvertible.ToDateTime(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToDateTime((float)this);
|
||||
}
|
||||
|
||||
decimal IConvertible.ToDecimal(IFormatProvider provider)
|
||||
decimal IConvertible.ToDecimal(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToDecimal((float)this);
|
||||
}
|
||||
|
||||
double IConvertible.ToDouble(IFormatProvider provider)
|
||||
double IConvertible.ToDouble(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToDouble((float)this);
|
||||
}
|
||||
|
||||
short IConvertible.ToInt16(IFormatProvider provider)
|
||||
short IConvertible.ToInt16(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToInt16((float)this);
|
||||
}
|
||||
|
||||
int IConvertible.ToInt32(IFormatProvider provider)
|
||||
int IConvertible.ToInt32(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToInt32((float)this);
|
||||
}
|
||||
|
||||
long IConvertible.ToInt64(IFormatProvider provider)
|
||||
long IConvertible.ToInt64(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToInt64((float)this);
|
||||
}
|
||||
|
||||
sbyte IConvertible.ToSByte(IFormatProvider provider)
|
||||
sbyte IConvertible.ToSByte(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToSByte((float)this);
|
||||
}
|
||||
|
||||
float IConvertible.ToSingle(IFormatProvider provider)
|
||||
float IConvertible.ToSingle(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToSingle((float)this);
|
||||
}
|
||||
|
||||
string IConvertible.ToString(IFormatProvider provider)
|
||||
string IConvertible.ToString(IFormatProvider? provider)
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
|
||||
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
|
||||
object IConvertible.ToType(Type conversionType, IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ChangeType((float)this, conversionType, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
ushort IConvertible.ToUInt16(IFormatProvider provider)
|
||||
ushort IConvertible.ToUInt16(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToUInt16((float)this);
|
||||
}
|
||||
|
||||
uint IConvertible.ToUInt32(IFormatProvider provider)
|
||||
uint IConvertible.ToUInt32(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToUInt32((float)this);
|
||||
}
|
||||
|
||||
ulong IConvertible.ToUInt64(IFormatProvider provider)
|
||||
ulong IConvertible.ToUInt64(IFormatProvider? provider)
|
||||
{
|
||||
return Convert.ToUInt64((float)this);
|
||||
}
|
||||
@ -366,10 +366,10 @@ namespace TWAINWorkingGroup
|
||||
#endregion
|
||||
|
||||
public static implicit operator float(TW_FIX32 value) => value.ToFloat();
|
||||
public static implicit operator TW_FIX32(float value) => new TW_FIX32(value);
|
||||
public static implicit operator TW_FIX32(float value) => new(value);
|
||||
|
||||
public static implicit operator double(TW_FIX32 value) => value.ToDouble();
|
||||
public static implicit operator TW_FIX32(double value) => new TW_FIX32((float)value);
|
||||
public static implicit operator TW_FIX32(double value) => new((float)value);
|
||||
|
||||
public static bool operator ==(TW_FIX32 value1, TW_FIX32 value2) => value1.Equals(value2);
|
||||
public static bool operator !=(TW_FIX32 value1, TW_FIX32 value2) => !value1.Equals(value2);
|
||||
@ -412,7 +412,7 @@ namespace TWAINWorkingGroup
|
||||
Right == other.Right && Bottom == other.Bottom;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is TW_FRAME other)
|
||||
{
|
||||
@ -453,7 +453,7 @@ namespace TWAINWorkingGroup
|
||||
}
|
||||
|
||||
public static implicit operator string(TW_STR32 value) => value.ToString();
|
||||
public static explicit operator TW_STR32(string value) => new TW_STR32(value);
|
||||
public static explicit operator TW_STR32(string value) => new(value);
|
||||
|
||||
}
|
||||
|
||||
@ -472,7 +472,7 @@ namespace TWAINWorkingGroup
|
||||
}
|
||||
|
||||
public static implicit operator string(TW_STR64 value) => value.ToString();
|
||||
public static explicit operator TW_STR64(string value) => new TW_STR64(value);
|
||||
public static explicit operator TW_STR64(string value) => new(value);
|
||||
}
|
||||
|
||||
partial struct TW_STR128
|
||||
@ -490,7 +490,7 @@ namespace TWAINWorkingGroup
|
||||
}
|
||||
|
||||
public static implicit operator string(TW_STR128 value) => value.ToString();
|
||||
public static explicit operator TW_STR128(string value) => new TW_STR128(value);
|
||||
public static explicit operator TW_STR128(string value) => new(value);
|
||||
}
|
||||
|
||||
partial struct TW_STR255
|
||||
@ -508,7 +508,7 @@ namespace TWAINWorkingGroup
|
||||
}
|
||||
|
||||
public static implicit operator string(TW_STR255 value) => value.ToString();
|
||||
public static explicit operator TW_STR255(string value) => new TW_STR255(value);
|
||||
public static explicit operator TW_STR255(string value) => new(value);
|
||||
}
|
||||
|
||||
partial struct TW_IDENTITY
|
||||
|
Loading…
Reference in New Issue
Block a user