bool SetFieldOrProperty(IAstAttribute aa, ExpressionPair p)
{
ReferenceExpression name = p.First as ReferenceExpression;
if (null == name)
{
_context.Errors.Add(CompilerErrorFactory.NamedParameterMustBeIdentifier(p));
return false;
}
else
{
Reflection.MemberInfo[] members = _type.FindMembers(
Reflection.MemberTypes.Property | Reflection.MemberTypes.Field,
Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public,
Type.FilterName, name.Name);
if (members.Length > 0)
{
if (members.Length > 1)
{
_context.Errors.Add(CompilerErrorFactory.AmbiguousReference(name, members));
return false;
}
else
{
Reflection.MemberInfo m = members[0];
Reflection.PropertyInfo property = m as Reflection.PropertyInfo;
if (null != property)
{
property.SetValue(aa, p.Second, null);
}
else
{
Reflection.FieldInfo field = m as Reflection.FieldInfo;
if (null != field)
{
field.SetValue(aa, p.Second);
}
else
{
throw new InvalidOperationException();
}
}
}
}
else
{
_context.Errors.Add(CompilerErrorFactory.NotAPublicFieldOrProperty(name, name.Name, _type.FullName));
return false;
}
}
return true;
}