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 + " невозможно преобразовать в один из поддерживаемых типов"); } }
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 + " невозможно преобразовать в один из поддерживаемых типов"); } }