Exemplo n.º 1
0
		protected virtual void Dispose( bool disposing )
		{
			DEBUG.IndentLine( "\n-- DynamicNode.Dispose( Disposing={0} ) - This={1}", disposing, this );

			_Host = null;
			_Parser = null;

			DEBUG.Unindent();
		}
Exemplo n.º 2
0
		// --------------------------------------------------
		/// <summary>
		/// Parses the dynamic lambda expression given in the form of a delegate, and creates and returns a new instance of
		/// <see cref="DynamicParser"/> to maintain the results.
		/// </summary>
		/// <param name="func">The dynamic lambda expression or delegate to parser.</param>
		/// <returns>The instance holding the results of the parsing.</returns>
		static public DynamicParser Parse( Delegate func )
		{
			DEBUG.IndentLine( "\n-- DynamicParser.Parse( Func )" );

			if( func == null ) throw new ArgumentNullException( "func", "Delegate to parse cannot be null." );
			DynamicParser parser = new DynamicParser();

			ParameterInfo[] pars = func.Method.GetParameters(); foreach( var par in pars ) {
				bool isdynamic = par.GetCustomAttributes( typeof( DynamicAttribute ), true ).Length != 0 ? true : false;
				if( isdynamic ) {
					var dyn = new DynamicNode.Argument( par.Name ) { _Parser = parser };
					parser._Arguments.Add( dyn );
				}
				else throw new ArgumentException( string.Format( "Argument '{0}' is not dynamic.", par.Name ) );
			}
			parser._Returned = func.DynamicInvoke( parser._Arguments.ToArray() );

			DEBUG.UnindentLine( "\n-- Parsed={0}", parser );
			return parser;
		}