2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-26 21:13:13 +00:00
This commit is contained in:
2025-05-30 18:00:10 +03:00
parent 276e7b17fd
commit a720b11959
10 changed files with 58 additions and 33 deletions

View File

@ -257,9 +257,9 @@ public static class Codec
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(DistributedPropertyContext<>))
if (genericType == typeof(PropertyContext<>))
{
valueOrSource = ((IDistributedPropertyContext)valueOrSource).GetValue(connection);
valueOrSource = ((IPropertyContext)valueOrSource).GetValue(connection);
}
else if (genericType == typeof(Func<>))
{

View File

@ -34,7 +34,7 @@ namespace Esiur.Data
public UUID(byte[] data, uint offset)
{
if (offset + 16 < data.Length)
if (offset + 16 > data.Length)
throw new Exception("UUID data size must be at least 16 bytes");
Data = DC.Clip(data, offset, 16);

View File

@ -1909,7 +1909,7 @@ partial class DistributedConnection
if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition()
== typeof(DistributedPropertyContext<>))
== typeof(PropertyContext<>))
{
value = Activator.CreateInstance(pi.PropertyType, this, value);
//value = new DistributedPropertyContext(this, value);

View File

@ -4,30 +4,30 @@ using System.Text;
namespace Esiur.Net.IIP;
public interface IDistributedPropertyContext
public interface IPropertyContext
{
object GetValue(DistributedConnection connection);
}
public class DistributedPropertyContext<T> : IDistributedPropertyContext
public class PropertyContext<T> : IPropertyContext
{
public T Value { get; private set; }
public DistributedConnection Connection { get; private set; }
public Func<DistributedConnection, T> Method { get; private set; }
public DistributedPropertyContext(DistributedConnection connection, T value)
public PropertyContext(DistributedConnection connection, T value)
{
this.Value = value;
this.Connection = connection;
}
public DistributedPropertyContext(Func<DistributedConnection, T> method)
public PropertyContext(Func<DistributedConnection, T> method)
{
this.Method = method;
}
public static implicit operator DistributedPropertyContext<T>(Func<DistributedConnection, T> method)
=> new DistributedPropertyContext<T>(method);
public static implicit operator PropertyContext<T>(Func<DistributedConnection, T> method)
=> new PropertyContext<T>(method);
public object GetValue(DistributedConnection connection)
{

View File

@ -352,7 +352,7 @@ public class Instance
*/
if (pt.PropertyInfo.PropertyType.IsGenericType
&& pt.PropertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(DistributedPropertyContext<>))
&& pt.PropertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(PropertyContext<>))
return false;

View File

@ -151,7 +151,7 @@ public class PropertyTemplate : MemberTemplate
{
var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null;
var propType = genericPropType == typeof(DistributedPropertyContext<>) ?
var propType = genericPropType == typeof(PropertyContext<>) ?
RepresentationType.FromType(pi.PropertyType.GetGenericArguments()[0]) :
RepresentationType.FromType(pi.PropertyType);
@ -174,7 +174,7 @@ public class PropertyTemplate : MemberTemplate
//var nullableAttr = pi.GetCustomAttribute<NullableAttribute>(true);
//var flags = ((byte[]) nullableAttr?.NullableFlags ?? new byte[0]).ToList();
if (nullableAttrFlags.Count > 0 && genericPropType == typeof(DistributedPropertyContext<>))
if (nullableAttrFlags.Count > 0 && genericPropType == typeof(PropertyContext<>))
nullableAttrFlags.RemoveAt(0);
if (nullableContextAttrFlag == 2)

View File

@ -191,7 +191,7 @@ public class TypeTemplate
var genericTypeArgs = type.GetGenericArguments();
if (genericType == typeof(List<>)
|| genericType == typeof(DistributedPropertyContext<>))
|| genericType == typeof(PropertyContext<>))
{
return GetDistributedTypes(genericTypeArgs[0]);
}