2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-26 21:13:13 +00:00

Resource Proxy

This commit is contained in:
2019-07-23 06:22:24 +03:00
parent 2d9f61c0d9
commit a2f4238933
12 changed files with 238 additions and 23 deletions

View File

@ -270,19 +270,22 @@ namespace Esiur.Resource
if (pt == null)
return false;
/*
#if NETSTANDARD1_5
var pi = resource.GetType().GetTypeInfo().GetProperty(name);
var pi = resource.GetType().GetTypeInfo().GetProperty(name, new[] { resource.GetType() });
#else
var pi = resource.GetType().GetProperty(pt.Name);
#endif
if (pi.PropertyType == typeof(DistributedPropertyContext))
*/
if (pt.Info.PropertyType == typeof(DistributedPropertyContext))
return false;
try
{
if (pi.CanWrite)
pi.SetValue(resource, DC.CastConvert(value, pi.PropertyType));
if (pt.Info.CanWrite)
pt.Info.SetValue(resource, DC.CastConvert(value, pt.Info.PropertyType));
}
catch(Exception ex)
{
@ -354,12 +357,16 @@ namespace Esiur.Resource
foreach (var pt in template.Properties)
{
/*
#if NETSTANDARD1_5
var pi = resource.GetType().GetTypeInfo().GetProperty(pt.Name);
#else
var pi = resource.GetType().GetProperty(pt.Name);
#endif
var rt = pi.GetValue(resource, null);
*/
var rt = pt.Info.GetValue(resource, null);
props.Add(new PropertyValue(rt, ages[pt.Index], modificationDates[pt.Index]));
}
@ -474,7 +481,7 @@ namespace Esiur.Resource
/// <param name="propertyName"></param>
/// <param name="newValue"></param>
/// <param name="oldValue"></param>
public void Modified([CallerMemberName] string propertyName = "")//, object newValue = null)//, object oldValue = null)
public void Modified([CallerMemberName] string propertyName = "")
{
object value;
if (GetPropertyValue(propertyName, out value))
@ -499,16 +506,20 @@ namespace Esiur.Resource
/// <returns>True, if the resource has the property.</returns>
public bool GetPropertyValue(string name, out object value)
{
/*
#if NETSTANDARD1_5
PropertyInfo pi = resource.GetType().GetTypeInfo().GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
#else
PropertyInfo pi = resource.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
#endif
*/
if (pi != null)
var pt = template.GetPropertyTemplate(name);
if (pt != null && pt.Info != null)
{
/*
#if NETSTANDARD1_5
object[] ca = pi.GetCustomAttributes(typeof(ResourceProperty), false).ToArray();
@ -523,6 +534,11 @@ namespace Esiur.Resource
// value = (value as Func<IManager, object>)(sender);
return true;
}
*/
value = pt.Info.GetValue(resource, null);
return true;
}
value = null;

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -17,6 +18,12 @@ namespace Esiur.Resource.Template
}
public PropertyInfo Info
{
get;
set;
}
//bool ReadOnly;
//IIPTypes::DataType ReturnType;
public PropertyPermission Permission {

View File

@ -126,6 +126,10 @@ namespace Esiur.Resource.Template
public ResourceTemplate(Type type)
{
if (type.Namespace.Contains("Esiur.Proxy.T"))
type = type.GetTypeInfo().BaseType;
// set guid
var typeName = Encoding.UTF8.GetBytes(type.FullName);
@ -156,7 +160,8 @@ namespace Esiur.Resource.Template
if (ps.Length > 0)
{
var pt = new PropertyTemplate(this, i++, pi.Name, ps[0].ReadExpansion, ps[0].WriteExpansion, ps[0].Storage);
properties.Add(pt);
pt.Info = pi;
properties.Add(pt);
}
}

View File

@ -24,6 +24,7 @@ SOFTWARE.
using Esiur.Data;
using Esiur.Engine;
using Esiur.Proxy;
using Esiur.Resource.Template;
using Esiur.Security.Permissions;
using System;
@ -347,8 +348,10 @@ namespace Esiur.Resource
}
public static T New<T>(string name, IStore store = null, IResource parent = null, IPermissionsManager manager = null)
where T:IResource
{
var res = Activator.CreateInstance(typeof(T)) as IResource;
var type = ResourceProxy.GetProxy<T>();
var res = Activator.CreateInstance(type) as IResource;
Put(res, name, store, parent, null, 0, manager);
return (T)res;
}