Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
EVALUATE() Equivalent function in .NET
Message
From
17/07/2007 20:03:02
 
 
To
17/07/2007 19:55:17
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01241330
Message ID:
01241356
Views:
34
It doesn't end there. Using the PemStatus below, that just tells you if it exists or not. Now you have to get the value:
object Var = this.GetType().GetProperty(VarName);
if (Var == null)
{
   sb.AppendFormat("<Property {0} not found>", VarName);
}
else
{
   // Got a valid property name - get its value as a string
   Var = this.GetType().GetProperty(VarName).GetValue(this, null);
   sb.AppendFormat("{0}",Var);
}
>Thanks. I'll check it out in detail. What I need to be able to do, is reproduce a sophisticated query builder that has lots of flexiblity. For example, retrieve records from a table where we have in a variable the record_id currently displayed. It gets tricky.
>
>Thanks again. I'll dig into this to learn more about reflection.
>
>Bob
>
>>Now it gets a lot more complicated. You have to create a property (not a field) and then you can check if that property exists with something like this:
>>
>>        public bool PemStatus(object o, string name, string PEM)
>>        {
>>            switch (PEM.ToUpper())
>>            {
>>                case "P":
>>                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(name);
>>                    if (pi == null)
>>                        return false;
>>                    else
>>                        return true;
>>                case "E":
>>                    System.Reflection.EventInfo ei = o.GetType().GetEvent(name);
>>                    if (ei == null)
>>                        return false;
>>                    else
>>                        return true;
>>                case "M":
>>                    System.Reflection.MethodInfo mi = o.GetType().GetMethod(name);
>>                    if (mi == null)
>>                        return false;
>>                    else
>>                        return true;
>>                default:
>>                    return false;
>>            }
>>        }
>>
>>
>>
>>So this is like Naomi said, you're using reflection.
>>
>>
>>>This function does look great if you know your variable in advance. But, that's why EVALUATE() is so powerful, because you don't have to know the variable in advance, you can pass a string "name" to it and it will evaluate it. For example:
>>>
>>>x = "company.name"
>>>y = EVALUATE(x)
>>>
>>>So the $64 question is, is there anything like that in C#?
>>>
>>>bob
>>>
>>>
>>>>You can use the StringBuilder class:
>>>>
>>>>StringBuilder sb = new StringBuilder();
>>>>sb.Append("SELECT *");
>>>>sb.AppendFormat(" FROM {0}",YourTableName);
>>>>sb.AppendFormat(" WHERE cName LIKE '{0}%'", WorkGroup);
>>>>sb.AppendFormat(" AND dIntervalStart >= '{0}' AND dIntervalStart < '{1}'", StartDate, EndDate);
>>>>sb.Append(" GROUP BY cName");
>>>>string sql = sb.ToString();
>>>>
>>>>SqlConnection cn = new SqlConnection(SqlDataSource);
>>>>SqlCommand cm = new SqlCommand(sql, cn);
>>>>
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Previous
Reply
Map
View

Click here to load this message in the networking platform