| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // System.Web.UI.DataBinder.cs
- //
- // Authors:
- // Duncan Mak ([email protected])
- // Gonzalo Paniagua Javier ([email protected])
- //
- // (C) 2002 Ximian, Inc. (http://www.ximian.com)
- //
- using System;
- using System.Reflection;
- namespace System.Web.UI {
- public sealed class DataBinder
- {
- public DataBinder ()
- {
- }
- public static object Eval (object container, string expression)
- {
- return GetPropertyValue (container, expression);
- }
- public static string Eval (object container, string expression, string format)
- {
- return GetPropertyValue (container, expression, format);
- }
- [MonoTODO]
- public static object GetIndexedPropertyValue (object container, string expr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public static string GetIndexedPropertyValue (object container, string expr, string format)
- {
- throw new NotImplementedException ();
- }
- public static object GetPropertyValue (object container, string propName)
- {
- if (container == null || propName == null)
- throw new ArgumentException ();
- Type type = container.GetType ();
- PropertyInfo prop = type.GetProperty (propName);
- if (prop == null)
- throw new HttpException ("Property " + propName + " not found in " +
- type.ToString ());
- MethodInfo getm = prop.GetGetMethod ();
- if (getm == null)
- throw new HttpException ("Cannot find get accessor for " + propName +
- " in " + type.ToString ());
-
- return getm.Invoke (container, null);
- }
- public static string GetPropertyValue (object container, string propName, string format)
- {
- object result;
- result = GetPropertyValue (container, propName);
- if (result == null)
- return String.Empty;
- if (format == null)
- return result.ToString ();
- return String.Format (format, result);
- }
- }
- }
|