Пример #1
0
        public override void SetIndexedValue(IValue index, IValue val)
        {
            var intIndex = (int)index.AsNumber();
            var newValue = COMWrapperContext.MarshalIValue(val);

            _array[intIndex] = newValue;
        }
Пример #2
0
 public IEnumerator <IValue> GetEnumerator()
 {
     for (int i = 0; i < _array.Length; i++)
     {
         yield return(COMWrapperContext.CreateIValue(_array[i]));
     }
 }
Пример #3
0
        public static IValue CreateIValue(object objParam)
        {
            if (objParam == null)
            {
                return(ValueFactory.Create());
            }

            var type = objParam.GetType();

            if (typeof(IValue).IsAssignableFrom(type))
            {
                return((IValue)objParam);
            }
            else if (type == typeof(string))
            {
                return(ValueFactory.Create((string)objParam));
            }
            else if (type == typeof(int))
            {
                return(ValueFactory.Create((int)objParam));
            }
            else if (type == typeof(double))
            {
                return(ValueFactory.Create((decimal)(double)objParam));
            }
            else if (type == typeof(DateTime))
            {
                return(ValueFactory.Create((DateTime)objParam));
            }
            else if (type == typeof(bool))
            {
                return(ValueFactory.Create((bool)objParam));
            }
            else if (type.IsArray)
            {
                return(new SafeArrayWrapper(objParam));
            }
            else if (IsObjectType(type))
            {
                COMWrapperContext ctx;
                try
                {
                    ctx = COMWrapperContext.Create(objParam);
                }
                catch (ArgumentException e)
                {
                    throw new RuntimeException("Тип " + type + " невозможно преобразовать в один из поддерживаемых типов", e);
                }
                return(ValueFactory.Create(ctx));
            }

            else
            {
                throw new RuntimeException("Тип " + type + " невозможно преобразовать в один из поддерживаемых типов");
            }
        }
Пример #4
0
        public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, System.Globalization.CultureInfo culture)
        {
            IRuntimeContextInstance inst = obj as IRuntimeContextInstance;

            if (inst == null)
            {
                throw new ArgumentException("Wrong argument type");
            }

            inst.SetPropValue(_dispId, COMWrapperContext.CreateIValue(value));
        }
Пример #5
0
        public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, System.Globalization.CultureInfo culture)
        {
            IRuntimeContextInstance inst = obj as IRuntimeContextInstance;

            if (inst == null)
            {
                throw new ArgumentException("Wrong argument type");
            }

            IValue retVal = inst.GetPropValue(_dispId);

            return(COMWrapperContext.MarshalIValue(retVal));
        }
Пример #6
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, System.Globalization.CultureInfo culture)
        {
            IRuntimeContextInstance inst = obj as IRuntimeContextInstance;

            if (inst == null)
            {
                throw new ArgumentException("Wrong argument type");
            }

            IValue[] engineParameters = parameters.Select(x => COMWrapperContext.CreateIValue(x)).ToArray();
            IValue   retVal           = null;

            inst.CallAsFunction(_dispId, engineParameters, out retVal);

            return(COMWrapperContext.MarshalIValue(retVal));
        }
Пример #7
0
        public static IValue CreateIValue(object objParam)
        {
            if (objParam == null)
            {
                return(ValueFactory.Create());
            }

            var type = objParam.GetType();

            if (typeof(IValue).IsAssignableFrom(type))
            {
                return((IValue)objParam);
            }
            else if (type == typeof(string))
            {
                return(ValueFactory.Create((string)objParam));
            }
            else if (type == typeof(int))
            {
                return(ValueFactory.Create((int)objParam));
            }
            else if (type == typeof(double))
            {
                return(ValueFactory.Create((decimal)objParam));
            }
            else if (type == typeof(DateTime))
            {
                return(ValueFactory.Create((DateTime)objParam));
            }
            else if (type == typeof(bool))
            {
                return(ValueFactory.Create((bool)objParam));
            }
            else if (DispatchUtility.ImplementsIDispatch(objParam))
            {
                var ctx = new COMWrapperContext(objParam);
                return(ValueFactory.Create(ctx));
            }
            else if (type.IsArray)
            {
                return(new SafeArrayWrapper(objParam));
            }
            else
            {
                throw new RuntimeException("Тип " + type + " невозможно преобразовать в один из поддерживаемых типов");
            }
        }
 public static IRuntimeContextInstance Constructor(IValue[] args)
 {
     return(COMWrapperContext.Create(args[0].AsString(), args.Skip(1).ToArray()));
 }
        public static IValue CreateIValue(object objParam)
        {
            if (objParam == null)
            {
                return(ValueFactory.Create());
            }

            var type = objParam.GetType();

            if (typeof(IValue).IsAssignableFrom(type))
            {
                return((IValue)objParam);
            }
            else if (type == typeof(string))
            {
                return(ValueFactory.Create((string)objParam));
            }
            else if (type == typeof(int) || type == typeof(uint) || type == typeof(byte) || type == typeof(sbyte) || type == typeof(short) || type == typeof(ushort))
            {
                return(ValueFactory.Create(System.Convert.ToInt32(objParam)));
            }
            else if (type == typeof(long) || type == typeof(ulong))
            {
                return(ValueFactory.Create(System.Convert.ToInt64(objParam)));
            }
            else if (type == typeof(double))
            {
                return(ValueFactory.Create((decimal)(double)objParam));
            }
            else if (type == typeof(DateTime))
            {
                var unboxed = (DateTime)objParam;
                if (unboxed == MIN_OLE_DATE)
                {
                    unboxed = DateTime.MinValue;
                }

                return(ValueFactory.Create(unboxed));
            }
            else if (type == typeof(bool))
            {
                return(ValueFactory.Create((bool)objParam));
            }
            else if (type.IsArray)
            {
                return(new SafeArrayWrapper(objParam));
            }
            else if (IsObjectType(type))
            {
                COMWrapperContext ctx;
                try
                {
                    ctx = COMWrapperContext.Create(objParam);
                }
                catch (ArgumentException e)
                {
                    throw new RuntimeException("Тип " + type + " невозможно преобразовать в один из поддерживаемых типов", e);
                }
                return(ValueFactory.Create(ctx));
            }

            else
            {
                throw new RuntimeException("Тип " + type + " невозможно преобразовать в один из поддерживаемых типов");
            }
        }
Пример #10
0
        public void SetValue(int index, IValue value)
        {
            var newValue = COMWrapperContext.MarshalIValue(value);

            _array[index] = newValue;
        }
Пример #11
0
 public IValue GetValue(int index)
 {
     return(COMWrapperContext.CreateIValue(_array[index]));
 }
Пример #12
0
        public override IValue GetIndexedValue(IValue index)
        {
            var intIndex = (int)index.AsNumber();

            return(COMWrapperContext.CreateIValue(_array[intIndex]));
        }