Пример #1
0
        DynamicMetaObject ISmalltalkDynamicMetaObjectProvider.PerformOperation(SmalltalkDynamicMetaObject target, string name, bool ignoreCase, int argumentCount, DynamicMetaObject[] args, out bool caseConflict)
        {
            throw new NotImplementedException();
            //bool localCaseConflict = false;
            //SmalltalkClass cls = this.Class;
            //Symbol na = null;
            //CompiledMethod method = MethodLookupHelper.LookupMethod(ref cls, ref na,
            //    c => c.InstanceBehavior.GetMethodByNativeName(name, argumentCount, ignoreCase, out localCaseConflict));

            //caseConflict = localCaseConflict;
            //if (localCaseConflict)
            //    return null;

            //if (method != null)
            //{
            //    MethodCompilationResult compilationResult = method.CompileInstanceMethod(cls.Runtime, cls, target.Expression, args.Select(dmo => dmo.Expression).ToArray(), null);
            //    return compilationResult.GetDynamicMetaObject(target.Restrictions);
            //}
            //return null;
        }
Пример #2
0
        private DynamicMetaObject GetSetMemberWorker(string name, bool ignoreCase, Type returnType, bool isSetValue, Func <MemberExpression, Expression> action, Func <DynamicMetaObject, DynamicMetaObject> fallback)
        {
            bool     caseConflict;
            IBinding binding = SmalltalkRuntimeDynamicMetaObject.GetMemberBinding(this.Runtime, name, ignoreCase, out caseConflict);

            if (caseConflict)
            {
                // The case-conflict exception
                return(new DynamicMetaObject(SmalltalkDynamicMetaObject.CreateCaseConflictException(
                                                 String.Format("Several methods exist with the name '{0}' and only differ in case.", name)), this.Restrictions));
            }

            string msg = null;

            if (binding == null)
            {
                msg = String.Format("The Smalltalk Runtime does not contain a class or global named '{0}'", name);
            }
            else if (isSetValue && !(binding is IWritableBinding))
            {
                msg = String.Format("The Smalltalk Runtime does not contain a global variable named '{0}'", name);
            }

            if (msg != null)
            {
                Expression errorSuggestion = Expression.Throw(
                    Expression.New(SmalltalkRuntimeDynamicMetaObject.InvalidOperationExceptionCtor, Expression.Constant(msg, typeof(String))), returnType);

                return(fallback(new DynamicMetaObject(errorSuggestion, this.Restrictions)));
            }

            MemberExpression value = Expression.Property(Expression.Constant(binding),
                                                         (isSetValue ? SmalltalkRuntimeDynamicMetaObject.SetValueProperty : SmalltalkRuntimeDynamicMetaObject.GetValueProperty));

            return(new DynamicMetaObject(Expression.Convert(action(value), returnType), this.Restrictions));
        }