Пример #1
0
		/////////////////////////////////////////////////////////////////////////////

		public static Invoker GetIndexerInvoker( object parent, string indexerName, TypeHelperDictionary typeHelpers )
		{
			// ******
			var objInfo = new ObjectInfo( parent, indexerName );
			if( objInfo.IsIndexer ) {
				return new IndexerInvoker( objInfo );
			}

			// ******
			INmpDynamic dyn = parent as INmpDynamic;
			if( null != dyn && dyn.HasIndexer(indexerName) ) {
				return new DynamicIndexerInvoker( parent, indexerName);
			}

			// ******
			object standin = typeHelpers.GetHelper( parent );
			if( null != standin ) {
				objInfo = new ObjectInfo( standin, indexerName );
				if( objInfo.IsIndexer ) {
					return new IndexerInvoker( objInfo );
				}
			}

			// ******
			return null;
		}
Пример #2
0
		/////////////////////////////////////////////////////////////////////////////
		
		//public static TypeHelperDictionary	TypeHelpers	{ get { return ThreadContext.TypeHelpers; } }


		/////////////////////////////////////////////////////////////////////////////

		public static Invoker GetMethodInvoker( object parent, string methodName, TypeHelperDictionary typeHelpers )
		{
			// ******
			var objInfo = new ObjectInfo( parent, methodName );
			if( objInfo.IsMethod ) {
				return new MethodInvoker( objInfo );
			}

			// ******
			INmpDynamic dyn = parent as INmpDynamic;
			if( null != dyn ) {
				if( dyn.HasMethod(methodName) ) {
					return new DynamicMethodInvoker( parent, methodName );
				}
			}

			// ******
			object standin = typeHelpers.GetHelper( parent );
			if( null != standin ) {
				objInfo = new ObjectInfo( standin, methodName );
				if( objInfo.IsMethod ) {
					return new MethodInvoker( objInfo );
				}
			}

			// ******
			return null;
		}
Пример #3
0
		/////////////////////////////////////////////////////////////////////////////

		public ExpressionEvaluatorBase( IMacroProcessor mp )
		{
			macroProcessor = mp;
			typeHelpers = mp.Get<TypeHelperDictionary>();
		}
Пример #4
0
		/////////////////////////////////////////////////////////////////////////////

		public static object EvalIndexerHelper( object objIn, object [] args, TypeHelperDictionary typeHelpers )
		{
			// ******
			//
			// expression:  macro[ ... ]
			//
			// expression:  macro.something[ x ][ y ], or macro.something( z )[ zz ]
			//
			object objResult = null;

			// ******
			Invoker invoker = objIn as Invoker;
			if( null != invoker ) {
				objResult = invoker.Invoke( args );
			}
			else {
				invoker = Invokers.GetDefaultIndexer( objIn, typeHelpers );
				if( null == invoker ) {
					ThreadContext.MacroError( "there is no default indexer for the object type \"{0}\"",  ObjectInfo.GetTypeName(objIn) );
				}
				objResult = invoker.Invoke( args );
			}

			// ******
			return objResult;
		}
Пример #5
0
		/////////////////////////////////////////////////////////////////////////////

		public static object EvalMemberHelper( object parent, string memberName, TypeHelperDictionary typeHelpers )
		{
			// ******
			object value;

			// ******
			var oo = new ObjectInfo( parent, memberName );
			if( null != (value = oo.GetValue()) ) {
				return value;
			}

			// ******
			INmpDynamic dyn = parent as INmpDynamic;
			if( null != dyn ) {
				NmpDynamicType dynType = dyn.HasMember( memberName );

				switch( dynType ) {
					case NmpDynamicType.None:
						break;

					case NmpDynamicType.Property:
						return DynamicPropertyInvoker.Invoke( parent, memberName );

					case NmpDynamicType.Indexer:
						return new DynamicIndexerInvoker( parent, memberName );

					case NmpDynamicType.Method:
						return new DynamicMethodInvoker( parent, memberName );
				}
			}

			// ******
			object standin = typeHelpers.GetHelper( parent );
			if( null != standin ) {
				oo = new ObjectInfo( standin, memberName );
				if( null != (value = oo.GetValue()) ) {
					return value;
				}
			}

			// ******
			return null;
		}
Пример #6
0
		/////////////////////////////////////////////////////////////////////////////

		public static Invoker GetDefaultIndexer( object parent, TypeHelperDictionary typeHelpers )
		{
			//
			// looks up default indexer name and then calls GetIndexerInvoker() - above
			//

			// ******
			Type objectType = ObjectInfo.GetObjectType( parent );
			object [] customAttrs = objectType.GetCustomAttributes( typeof(DefaultMemberAttribute), true );

			// ******
			string memberName = string.Empty;

			if( 0 == customAttrs.Length ) {
				//var methods = objectType.GetMethods();
				//if( 0 == methods.Length ) {
				//	return null;
				//}
				//
				//
				//is array use Get ??
				//
				//bool found = false;
				//foreach( MethodInfo method in methods ) {
				//	if( method.Name == "Item" ) {
				//		found = true;
				//		break;
				//	}
				//}
				//
				//if( ! found ) {
				//	return null;
				//}
				//
				//memberName = "Item";
				if( objectType.IsArray ) {
					memberName = "GetValue";
				}
				else {
					return null;
				}
			}
			else {
				memberName = ((DefaultMemberAttribute) customAttrs [ 0 ]).MemberName;
			}
			
			// ******
			return GetIndexerInvoker( parent, memberName, typeHelpers );
		}