private void InitByInstance()
 {
     if (!DispatchUtility.ImplementsIDispatch(_instance))
     {
         _instance = null;
         throw new RuntimeException("Объект не реализует IDispatch.");
     }
 }
Example #2
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 + " невозможно преобразовать в один из поддерживаемых типов");
            }
        }
Example #3
0
        private void InitByInstance()
        {
            if (!DispatchUtility.ImplementsIDispatch(_instance))
            {
                _instance = null;
                throw new RuntimeException("Объект не реализует IDispatch.");
            }

            try
            {
                _dispatchedType = DispatchUtility.GetType(_instance, false);
            }
            catch
            {
                _instance = null;
                throw;
            }
        }