|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ObjectPresentation
{
public class FieldInputValueViewModel : InputValueViewModel
{
#region Constructors
public FieldInputValueViewModel(FieldInfo fi)
: this(fi, 0)
{
}
public FieldInputValueViewModel(FieldInfo fi, int valueLevel)
{
ValueLevel = valueLevel;
FieldInformation = fi;
}
#endregion
#region Properties
#region FieldInformation
private FieldInfo _fieldInformation;
public FieldInfo FieldInformation
{
protected get { return _fieldInformation; }
set
{
if (_fieldInformation != value)
{
FieldInfo oldValue = _fieldInformation;
_fieldInformation = value;
OnFieldInformationChanged(oldValue, _fieldInformation);
}
}
}
protected virtual void OnFieldInformationChanged(FieldInfo oldValue, FieldInfo newValue)
{
if (newValue == null)
{
return;
}
Name = newValue.Name;
ValueType = newValue.FieldType;
}
#endregion
#endregion
protected override void SetObjectFieldValue(object o)
{
if (o == null)
{
return;
}
Type objectType = o.GetType();
FieldInfo objectField = objectType.GetField(Name);
try
{
objectField.SetValue(o, GetValue());
}
catch (Exception ex)
{
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.