private bool TryHandleSpecialCase(Expression expression, List<object> argumentValues, Type[] argumentTypes, CodeContext codeContext, string invocation, object caller, out object result)
{
result = null;
bool handled = false;
if (expression is MemberReferenceExpression)
{
MemberReferenceExpression mre = expression as MemberReferenceExpression;
if(mre.MemberName == "Call" &&
argumentValues.Count == 1 && argumentValues[0] is ExecuteScriptInstruction)
{
if (caller != null && caller is PositionedObject)
{
// call the ExecuteScriptInstruction itself - it has a After method so it can handle whatever.
result = argumentValues[0];
handled = true;
}
}
if (!handled)
{
if (caller != null && caller is ElementRuntime)
{
handled = TryHandleElementRuntimeSpecialCases(argumentValues, argumentTypes, caller as ElementRuntime, ref result, mre);
}
}
if (!handled && caller is IElement)
{
if (mre.MemberName == "GetFile")
{
IElement element = caller as IElement;
//ReferencedFileSave rfs = element.GetReferencedFileSaveByInstanceName(argumentValues[0] as string);
IElement containerInstance = null;
if (codeContext.ContainerInstance != null)
{
if (codeContext.ContainerInstance is ElementRuntime)
{
containerInstance = (codeContext.ContainerInstance as ElementRuntime).AssociatedIElement;
}
}
if (element == containerInstance)
{
result = (codeContext.ContainerInstance as ElementRuntime).GetReferencedFileSaveRuntime(argumentValues[0] as string);
handled = true;
}
}
}
if (!handled && caller.GetType().Name == "SetHolder`1")
{
MethodInfo methodInfo;
// let's invoke this regularly, but add it to the container
GetMethodInfo(expression, argumentValues, argumentTypes, codeContext, invocation, caller, out methodInfo);
if (methodInfo != null)
{
result = methodInfo.Invoke(caller, argumentValues.ToArray());
// no need to do anything?
//if (result is Instruction)
//{
// ((result as Instruction).Target as IInstructable).Instructions.Add(result as Instruction);
//}
handled = true;
}
}
}
return handled;
}