public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            try
            {
                var propIdx = FindProperty(binder.Name);
                if (!IsPropReadable(propIdx))
                {
                    result = null;
                    return(false);
                }

                result = ContextValuesMarshaller.ConvertToCLRObject(GetPropValue(propIdx));
                return(true);
            }
            catch (PropertyAccessException)
            {
                result = null;
                return(false);
            }
            catch (ValueMarshallingException)
            {
                result = null;
                return(false);
            }
        }
        protected static object[] MarshalArgumentsStrict(System.Reflection.MethodInfo method, IValue[] arguments)
        {
            var parameters = method.GetParameters();

            object[] marshalledArgs = new object[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                if (i < arguments.Length)
                {
                    if (IsMissedArg(arguments[i]) && parameters[i].IsOptional)
                    {
                        marshalledArgs[i] = Type.Missing;
                    }
                    else
                    {
                        marshalledArgs[i] = ContextValuesMarshaller.ConvertParam(arguments[i], parameters[i].ParameterType);
                    }
                }
                else
                {
                    marshalledArgs[i] = Type.Missing;
                }
            }

            return(marshalledArgs);
        }
Beispiel #3
0
            private static T ConvertParam <T>(IValue value, object def)
            {
                if (value == null || value.DataType == DataType.NotAValidValue)
                {
                    return((T)def);
                }

                return(ContextValuesMarshaller.ConvertParam <T>(value));
            }
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            if (!IsIndexed)
            {
                return(false);
            }

            var index = ContextValuesMarshaller.ConvertReturnValue(indexes[0], indexes[0].GetType());

            SetIndexedValue(index, ContextValuesMarshaller.ConvertReturnValue(value, value.GetType()));
            return(true);
        }
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (!IsIndexed)
            {
                result = null;
                return(false);
            }

            var index = ContextValuesMarshaller.ConvertReturnValue(indexes[0], indexes[0].GetType());

            result = ContextValuesMarshaller.ConvertToCLRObject(GetIndexedValue(index));
            return(true);
        }
        protected static object[] MarshalArgumentsStrict(IValue[] arguments, Type[] argumentsTypes)
        {
            if (argumentsTypes.Length < arguments.Length)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            object[] marshalledArgs = new object[arguments.Length];
            for (int i = 0; i < arguments.Length; i++)
            {
                marshalledArgs[i] = ContextValuesMarshaller.ConvertParam(arguments[i], argumentsTypes[i]);
            }

            return(marshalledArgs);
        }
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            try
            {
                var propIdx = FindProperty(binder.Name);
                if (IsPropWritable(propIdx))
                {
                    return(false);
                }

                SetPropValue(propIdx, ContextValuesMarshaller.ConvertReturnValue(value, value.GetType()));

                return(true);
            }
            catch (PropertyAccessException)
            {
                return(false);
            }
            catch (NotSupportedException)
            {
                return(false);
            }
        }
        public static object MarshalIValue(IValue val)
        {
            object retValue;

            if (val.DataType == Machine.DataType.Date)
            {
                var date = val.AsDate();
                if (date <= MIN_OLE_DATE)
                {
                    retValue = MIN_OLE_DATE;
                }
                else
                {
                    retValue = date;
                }
            }
            else
            {
                retValue = ContextValuesMarshaller.ConvertToCLRObject(val);
            }

            return(retValue);
        }
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            int methIdx;

            try
            {
                methIdx = FindMethod(binder.Name);
            }
            catch (MethodAccessException)
            {
                result = null;
                return(false);
            }

            var methInfo   = GetMethodInfo(methIdx);
            var valueArgs  = new IValue[methInfo.Params.Length];
            var passedArgs = args.Select(x => ContextValuesMarshaller.ConvertReturnValue(x, x.GetType())).ToArray();

            for (int i = 0; i < valueArgs.Length; i++)
            {
                if (i < passedArgs.Length)
                {
                    valueArgs[i] = passedArgs[i];
                }
                else
                {
                    valueArgs[i] = ValueFactory.CreateInvalidValueMarker();
                }
            }

            IValue methResult;

            CallAsFunction(methIdx, valueArgs, out methResult);
            result = methResult == null? null : ContextValuesMarshaller.ConvertToCLRObject(methResult);

            return(true);
        }
Beispiel #10
0
 private IValue ConvertReturnValue <TRet>(TRet param)
 {
     return(ContextValuesMarshaller.ConvertReturnValue <TRet>(param));
 }
Beispiel #11
0
 private T ConvertParam <T>(IValue value)
 {
     return(ContextValuesMarshaller.ConvertParam <T>(value));
 }
Beispiel #12
0
 public static object MarshalIValue(IValue val)
 {
     return(ContextValuesMarshaller.ConvertToCLRObject(val));
 }