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:
2019-11-10 12:41:31 +03:00
parent 8d06fd05ad
commit 5e87ea5247
41 changed files with 2076 additions and 431 deletions

View File

@ -96,7 +96,7 @@ namespace Esiur.Data
public AutoList(ST state)
{
this.state = state;
#if NETSTANDARD1_5
#if NETSTANDARD
removableList = (typeof(IDestructible).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()));
#else
removableList = (typeof(IDestructible).IsAssignableFrom(typeof(T)));
@ -111,7 +111,7 @@ namespace Esiur.Data
public AutoList(ST state, T[] values)
{
this.state = state;
#if NETSTANDARD1_5
#if NETSTANDARD
removableList = (typeof(IDestructible).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()));
#else
removableList = (typeof(IDestructible).IsAssignableFrom(typeof(T)));

View File

@ -62,7 +62,7 @@ namespace Esiur.Data
list.Add((byte)i);
else
{
#if NETSTANDARD1_5
#if NETSTANDARD
MethodInfo mi = typeof(DC).GetTypeInfo().GetMethod("ToBytes", new Type[] { i.GetType() });
#else
MethodInfo mi = typeof(DC).GetMethod("ToBytes", new Type[] { i.GetType() });
@ -100,7 +100,7 @@ namespace Esiur.Data
list.Add((byte)i);
else
{
#if NETSTANDARD1_5
#if NETSTANDARD
MethodInfo mi = typeof(DC).GetTypeInfo().GetMethod("ToBytes", new Type[] { i.GetType() });
#else
MethodInfo mi = typeof(DC).GetMethod("ToBytes", new Type[] { i.GetType() });
@ -138,7 +138,7 @@ namespace Esiur.Data
}
else
{
#if NETSTANDARD1_5
#if NETSTANDARD
MethodInfo mi = typeof(DC).GetTypeInfo().GetMethod("ToBytes", new Type[] { i.GetType() });
#else
MethodInfo mi = typeof(DC).GetMethod("ToBytes", new Type[] { i.GetType() });

View File

@ -34,6 +34,7 @@ using Esiur.Resource;
using System.Linq;
using System.Reflection;
using Esiur.Resource.Template;
using System.Runtime.CompilerServices;
namespace Esiur.Data
{
@ -171,7 +172,7 @@ namespace Esiur.Data
var result = (StructureComparisonResult)data[offset++];
IAsyncReply<Structure> previous = null;
AsyncReply<Structure> previous = null;
// string[] previousKeys = null;
// DataType[] previousTypes = null;
@ -1064,6 +1065,16 @@ namespace Esiur.Data
return rt.ToArray();
}
public static bool IsAnonymous(Type type)
{
// Detect anonymous types
var info = type.GetTypeInfo();
var hasCompilerGeneratedAttribute = info.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Count() > 0;
var nameContainsAnonymousType = type.FullName.Contains("AnonymousType");
return hasCompilerGeneratedAttribute && nameContainsAnonymousType;
}
/// <summary>
/// Check if a type implements an interface
/// </summary>
@ -1086,7 +1097,7 @@ namespace Esiur.Data
if (type == iface)
return true;
#if NETSTANDARD1_5
#if NETSTANDARD
if (type.GetTypeInfo().GetInterfaces().Contains(iface))// (x=>x.GetTypeInfo().IsGenericType (iface))
return true;
@ -1109,7 +1120,7 @@ namespace Esiur.Data
if (type == iface)
return true;
#if NETSTANDARD1_5
#if NETSTANDARD
if (type.GetTypeInfo().GetInterfaces().Contains(iface))
return true;
@ -1137,7 +1148,7 @@ namespace Esiur.Data
{
if (childType == parentType)
return true;
#if NETSTANDARD1_5
#if NETSTANDARD
childType = childType.GetTypeInfo().BaseType;
#else
childType = childType.BaseType;

View File

@ -67,7 +67,7 @@ namespace Esiur.Data
{
try
{
#if NETSTANDARD1_5
#if NETSTANDARD
if (destinationType.GetTypeInfo().IsInstanceOfType(v.GetValue(i)))
#else
if (destinationType.IsInstanceOfType(v.GetValue(i)))
@ -97,7 +97,7 @@ namespace Esiur.Data
destinationType = underType;
}
#if NETSTANDARD1_5
#if NETSTANDARD
if (destinationType.GetTypeInfo().IsInstanceOfType(value))
#else
if (destinationType.IsInstanceOfType(value))
@ -589,7 +589,7 @@ namespace Esiur.Data
{
try
{
#if NETSTANDARD1_5
#if NETSTANDARD
var tryParse = typeof(T).GetTypeInfo().GetDeclaredMethod("TryParse");
if ((bool)tryParse.Invoke(null, new object[] { Input, null }))
{

View File

@ -220,7 +220,7 @@ namespace Esiur.Data
public KeyList(object owner = null)
{
#if NETSTANDARD1_5
#if NETSTANDARD
removableList = (typeof(IDestructible).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()));
#else
removableList = (typeof(IDestructible).IsAssignableFrom(typeof(T)));

View File

@ -31,6 +31,7 @@ using System.Threading.Tasks;
using Esiur.Data;
using Esiur.Misc;
using Esiur.Core;
using System.Reflection;
namespace Esiur.Data
{
@ -61,6 +62,26 @@ namespace Esiur.Data
return rt.TrimEnd('\r', '\n');
}
public static Structure FromObject(object obj)
{
var type = obj.GetType();
if (obj is Structure)
return obj as Structure;
else if (Codec.IsAnonymous(type))
{
var st = new Structure();
var pi = type.GetTypeInfo().GetProperties();
foreach (var p in pi)
st[p.Name] = p.GetValue(obj);
return st;
}
else
return null;
}
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return dic.GetEnumerator();