VxFormGenerator.Core
ValueReference.cs
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace VxFormGenerator.Core
{
public clast FormElementReference
{
private TValue _value;
public TValue Value
{
get
{
return _value;
}
set
{
_value = value;
if (ValueChanged.HasDelegate)
ValueChanged.InvokeAsync(_value);
}
}
public EventCallback ValueChanged { get; set; }
public Expression ValueExpression { get; internal set; }
public Layout.VxFormElementDefinition FormColumnDefinition { get; set; }
public static void SetValue(object model, string key, TValue value)
{
var modelType = model.GetType();
if (modelType == typeof(ExpandoObject))
{
var accessor = ((IDictionary)model);
accessor[key] = value;
}
else
{
var propertyInfo = modelType.GetProperty(key);
propertyInfo.SetValue(model, value);
}
}
public static TValue GetValue(object model, string key)
{
var modelType = model.GetType();
if (modelType == typeof(ExpandoObject))
{
var accessor = ((IDictionary)model);
return (TValue)accessor[key];
}
else
{
var propertyInfo = modelType.GetProperty(key);
return (TValue) propertyInfo.GetValue(model);
}
}
}
public clast ValueReference
{
public TValue Value { get; set; }
public TKey Key { get; set; }
}
public clast ValueReferences : ValueReferences
{
public ValueReferences()
{
var values = typeof(T).GetEnumValues()
.Cast()
.Select(m => new ValueReference() { Key = m.ToString(), Value = false })
.ToList();
this.AddRange(values);
}
}
public clast ValueReferences : List
{
}
}