Castle.MonoRail.Framework.Views.Aspx.BindingContext.ResolveSymbol C# (CSharp) Method

ResolveSymbol() public method

Resolves the symbol.
public ResolveSymbol ( string symbolName, bool throwIfNotFound ) : object
symbolName string Name of the symbol.
throwIfNotFound bool if set to true [throw if not found].
return object
		public object ResolveSymbol(string symbolName, bool throwIfNotFound)
		{
			object value = null;

			foreach(IBindingScope scope in scopes)
			{
				value = scope.ResolveSymbol(symbolName);
				if (value != null) break;
			}

			if (value == null && throwIfNotFound)
			{
				throw new InvalidOperationException("Unable to resolve symbol " + symbolName);
			}

			return value;
		}

Usage Example

		private object PerformDataBinding(string expression, BindingContext context, bool ignoreErrors)
		{
			object value;
			int index = expression.IndexOf('.');

			if (index > 0)
			{
				string symbolName = expression.Substring(0, index).Trim();

				value = context.ResolveSymbol(symbolName, !ignoreErrors);

				if (value != null)
				{
					expression = expression.Substring(index + 1).Trim();

					try
					{
						value = PerformDataBinding(value, expression, context);
					}
					catch
					{
						if (!ignoreErrors) throw;
						value = null;
					}
				}
			}
			else
			{
				value = context.ResolveSymbol(expression, !ignoreErrors);
			}

			return value;
		}