///
/// <summary>
/// Parses identifiers (fields or properties)
/// </summary>
///
/// <param name="environment">The environment containing the field or property</param>
/// <param name="data">The name of the field or property</param>
///
/// <returns>An CseObject containing the value of the identifier or containing null if identifier cannot be found</returns>
///
/// <exception cref="CseLogicExceptionType.IDENT_NOT_FOUND" />
///
internal static CseObject Parse(CseObject environment, string data)
{
if (data[0].Equals('@'))
{
data = data.Remove(0, 1);
}
LiteralExp.ParseEscSeqs(ref data, false);
CseObject result = null;
Type instanceType = TypeExp.GetTypeObj(environment.Value);
if (!instanceType.IsEnum)
{
if (environment == CsEval.EvalEnvironment)
{
CseObject tempLookup = TempIdentifierExp.Lookup(data);
if (tempLookup != null)
{
return(tempLookup);
}
}
FieldInfo fieldInfo = instanceType.GetField(data, defaultFlags | BindingFlags.GetField);
if (fieldInfo != null)
{
result = new CseObject(fieldInfo.GetValue(environment.Value));
result.CompileTimeType = fieldInfo.FieldType;
}
else
{
PropertyInfo propertyInfo = instanceType.GetProperty(data, defaultFlags | BindingFlags.GetProperty);
if (propertyInfo != null)
{
result = new CseObject(propertyInfo.GetValue(environment.Value, null));
result.CompileTimeType = propertyInfo.PropertyType;
}
else
{
Type t = TypeExp.GetType(data);
if (t != null)
{
result = new CseObject(t);
result.CompileTimeType = t.GetType();
}
else
{
throw new CseLogicException(CseLogicExceptionType.IDENT_NOT_FOUND, data);
}
}
}
}
else
{
dynamic resultObj = Enum.Parse(instanceType, data);
result = new CseObject(resultObj);
result.CompileTimeType = resultObj.GetType();
}
return(result);
}