Exemplo n.º 1
0
Arquivo: APC.cs Projeto: abel/sinan
 public Apc(Variant config)
 {
     ID = config.GetStringOrDefault("_id");
     this.Name = config.GetStringOrDefault("Name");
     Name = config.GetStringOrDefault("Name");
     m_value = config.GetVariantOrDefault("Value");
     m_life = new PlayerProperty();
     if (m_value != null)
     {
         m_life.Add(m_value);
         this.Level = m_value.GetIntOrDefault("Level");
     }
     this.ApcType = FighterType.APC;
     Variant ui = config.GetVariantOrDefault("UI");
     if (ui != null)
     {
         this.Skin = ui.GetStringOrDefault("Skin");
         string apcType = ui.GetStringOrDefault("Type");
         if (apcType == "BB")
         {
             this.ApcType = FighterType.BB;
         }
         else if (apcType == "Boss")
         {
             this.ApcType = FighterType.Boss;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 学习宠物技能(御宠图鉴)
        /// </summary>
        /// <param name="variant"></param>
        public bool AddPetBook(Variant c)
        {
            string skillID = c.GetStringOrDefault("SkillID");
            if (string.IsNullOrEmpty(skillID)) return false;

            int level = c.GetIntOrDefault("SkillLev");
            var skill = m_petBook.Value.GetValueOrDefault<List<object>>(skillID);
            if (skill == null)
            {
                skill = new List<object>();
                m_petBook.Value[skillID] = skill;
            }
            if (skill.Contains(level))
            {
                return false;
            }
            int mustslevel = level - 1;
            if (mustslevel > 0 && (!skill.Contains(mustslevel)))
            {
                return false;
            }
            skill.Add(level);
            m_petBook.Save();
            this.Call(ClientCommand.UpdateActorR, new PlayerExDetail(m_petBook));
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// GM取得拍卖行数据
        /// </summary>
        /// <param name="note"></param>
        /// <param name="strs"></param>
        public static void GMAuctionList(GMNote note, string[] strs)
        {
            if (strs.Length < 3)
                return;
            PlayerBusiness player = PlayersProxy.FindPlayerByName(strs[0].Trim());
            if (player == null)
                return;
            int pageIndex = 0;

            if (!int.TryParse(strs[1].Trim(), out pageIndex))
                return;
            int pageSize = 6;

            int total = 0;
            int curIndex = 0;
            List<Auction> auctionList = AuctionAccess.Instance.AuctionSellerList(player.ID, pageSize, pageIndex, out total, out curIndex);
            List<Variant> list = new List<Variant>();
            foreach (Auction model in auctionList)
            {
                Variant mv = model.Value;
                Variant v = new Variant();
                foreach (var item in mv)
                {
                    v.Add(item.Key, item.Value);
                }
                v.Add("ID", model.ID);
                v.Add("Name", model.Name);
                list.Add(v);
            }
            note.Call(GMCommand.GMAuctionListR, list, total, curIndex);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加点券
        /// </summary>
        /// <param name="bond"></param>
        /// <param name="eType"></param>
        /// <param name="des"></param>
        /// <returns></returns>
        public bool AddBond(int bond, FinanceType ft, string remark = null)
        {
            if (bond != 0)
            {
                BsonDocument modified = PlayerAccess.Instance.SafeUpdate(_id, "Bond", bond);
                if (modified == null)
                {
                    return false;
                }
                long newBond = Convert.ToInt64(modified["Bond"]);
                this.Bond = newBond;
                Variant v = new Variant(2);
                v.Add("Bond", this.Bond);

                this.UpdataActorR(v);
                //写日志
                PayLog log = new PayLog(ServerLogger.zoneid, Actiontype.Bond);
                log.modifyfee = bond;
                log.totalfee = newBond;
                log.toopenid = UserID;
                log.touid = PID;
                log.reserve_1 = (int)ft;
                log.remark = remark;
                this.WriteLog(log);
            }
            return true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 判断是否存在要求回收的物品
        /// </summary>
        /// <param name="note"></param>
        /// <param name="s"></param>
        /// <returns>true表示发生变化</returns>
        public static bool Task10004(UserNote note, Variant s)
        {
            if (s.GetIntOrDefault("Cur") == s.GetIntOrDefault("Total"))
                return false;
            if (!s.ContainsKey("GoodsID"))
                return false;

            if (s.GetIntOrDefault("Type") != 10004)
                return false;

            int m = GameConfigAccess.Instance.GetStactCount(s.GetStringOrDefault("GoodsID"));

            if (m <= 0) return false;

            PlayerEx burden = note.Player.B0;

            IList c = burden.Value.GetValue<IList>("C");
            int number = 0;
            foreach (Variant d in c)
            {
                if (d.GetStringOrDefault("G") == s.GetStringOrDefault("GoodsID"))
                {
                    number += d.GetIntOrDefault("A");
                }
            }

            if (number >= s.GetIntOrDefault("Total"))
                s["Cur"] = s.GetIntOrDefault("Total");
            else
                s["Cur"] = number;
            return true;
        }
Exemplo n.º 6
0
 public int WriteDaily(string key, string id)
 {
     int day = DateTime.Now.DayOfYear;
     ClearDaily(day);
     Variant log = m_daily.Value.GetVariantOrDefault(key);
     //同一天的..
     if (log == null)
     {
         log = new Variant();
         m_daily.Value[key] = log;
     }
     else
     {
         //删除过期的.
         ClearDaily(day);
     }
     //前面的为次数.后10位为日期
     int old = log.GetIntOrDefault(id);
     int count = old >> 10;
     if (day == (old & 0X1FF)) //365小于1FF.
     {
         log[id] = (((count + 1) << 10) | day);
     }
     else
     {
         log[id] = (1 << 10) | day;
     }
     m_daily.Save();
     this.Call(ClientCommand.UpdateActorR, new PlayerExDetail(m_daily));
     return count + 1;
 }
Exemplo n.º 7
0
 public static Point NewPoint(Variant point)
 {
     if (point == null) return Point.Empty;
     int x = point.GetIntOrDefault("X");
     int y = point.GetIntOrDefault("Y");
     return new Point(x, y);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 取得领奖情况信息
        /// </summary>
        /// <returns></returns>
        public Variant GetAwardMsg(Player player)
        {
            Variant v = new Variant();
            for (int i = 0; i < 3; i++)
            {
                string str = "";
                if (i == 0)
                {
                    str = "MonthAward";
                }
                else if (i == 1)
                {
                    str = "WeekAward";
                }
                else
                {
                    str = "DayAward";
                }

                string tableName = "Player" + GetTableName(str);
                if (IsAward(player, tableName, str))
                {
                    v[str] = -1;//表示已经领取
                }
                else
                {
                    //得到排名
                    v[str] = GetMyRank(player, tableName);
                }
            }
            return v;
        }
Exemplo n.º 9
0
 public DocData()
 {
     Properties = new NameValueCollection();
     Files = new NameValueCollection();
     DocComments = new Dictionary<string, DocComment>();
     Global = new Variant();
 }
Exemplo n.º 10
0
        public void TestBagAdd()
        {
            Variant v = new Variant(Variant.EnumType.Bag);

            Assert.Throws<VariantException>(delegate { v.Add(new Variant()); });
            Assert.Throws<VariantException>(delegate { v.Add(new DateTime(0), new Variant()); });

            v.Add("key1", new Variant("value1"));
            v.Add("key2", new Variant(1.0));
            v.Add("key1", new Variant("value2"));

            Assert.AreEqual(v.Count, 3);
            Assert.IsFalse(v.Empty);

            Assert.IsTrue(v.ContainsKey("key1"));
            Assert.IsTrue(v.ContainsKey("key2"));

            Assert.AreEqual(v["key1"].Type, Variant.EnumType.String);
            Assert.AreEqual(v["key1"].As<string>(), "value1");
            Assert.AreEqual(v["key2"].Type, Variant.EnumType.Double);
            Assert.AreEqual(v["key2"].As<double>(), 1.0);

            v["key1"] = new Variant("other");
            Assert.AreEqual(v["key1"].As<string>(), "other");

            v.Remove("key1");
            Assert.AreEqual(1, v.Count);

            v.Remove("key2");
            Assert.AreEqual(v.Count, 0);
            Assert.IsTrue(v.Empty);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 初始化固定技能
        /// </summary>
        /// <param name="skills"></param>
        /// <returns></returns>
        public static Dictionary<string, Tuple<int, GameConfig>> InitFixBuffer(Variant skills)
        {
            Dictionary<string, Tuple<int, GameConfig>> fixBuffer = null;
            if (skills != null)
            {
                fixBuffer = new Dictionary<string, Tuple<int, GameConfig>>();
                foreach (var s in skills)
                {
                    GameConfig gs = GameConfigAccess.Instance.FindOneById(s.Key);
                    if (gs == null || gs.Name == null) continue;

                    string name = gs.Name.Replace(PetSkillSuffix, string.Empty);
                    if (fixBuffer.ContainsKey(name)) continue;

                    if (gs.SubType == SkillSub.AddAttack || gs.SubType == SkillSub.AddBuffer || gs.SubType == SkillSub.IncreaseBuffer)
                    {
                        //发动类型 被动0/ 主动大于1(冷切回合数)
                        if (gs.UI.GetIntOrDefault("MaxUse") == 0)
                        {
                            fixBuffer.Add(name, new Tuple<int, GameConfig>(Convert.ToInt32(s.Value), gs));
                        }
                    }
                }
            }
            return fixBuffer;
        }
Exemplo n.º 12
0
        public void TestListAdd()
        {
            Variant v = new Variant(Variant.EnumType.List);

            Assert.Throws<VariantException>(delegate { v.Add("key", new Variant()); });
            Assert.Throws<VariantException>(delegate { v.Add(new DateTime(0), new Variant()); });

            v.Add(new Variant("value1"));
            v.Add(new Variant(2.0));

            Assert.AreEqual(v.Count, 2);
            Assert.IsFalse(v.Empty);

            Assert.AreEqual(Variant.EnumType.String, v[0].Type);
            Assert.AreEqual("value1", v[0].As<string>());
            Assert.AreEqual(Variant.EnumType.Double, v[1].Type);
            Assert.AreEqual(2.0, v[1].As<double>());

            Assert.Throws<VariantException>(delegate { Variant w = v[-1]; });
            Assert.Throws<VariantException>(delegate { Variant w = v[2]; });

            v[0] = new Variant("other");
            Assert.AreEqual(v[0].As<string>(), "other");

            v.Clear();
            Assert.AreEqual(v.Count, 0);
            Assert.IsTrue(v.Empty);
        }
Exemplo n.º 13
0
        /// <summary>
        /// GM取得拍卖行数据
        /// </summary>
        /// <param name="note"></param>
        public static object GMAuctionList(Notification note)
        {
            string[] strs = GMBusiness.GetCommand(note);
            if (strs.Length < 3)
                return null;
            PlayerBusiness player = PlayersProxy.FindPlayerByName(strs[0].Trim());
            if (player == null)
                return null;
            int pageIndex = 0;

            if (!int.TryParse(strs[1].Trim(), out pageIndex))
                return null;
            int pageSize = 6;

            int total = 0;
            int curIndex = 0;
            List<Auction> auctionList = AuctionAccess.Instance.AuctionSellerList(player.ID, pageSize, pageIndex, out total, out curIndex);
            List<Variant> list = new List<Variant>();
            foreach (Auction model in auctionList)
            {
                Variant mv = model.Value;
                Variant v = new Variant();
                foreach (var item in mv)
                {
                    v.Add(item.Key, item.Value);
                }
                v.Add("ID", model.ID);
                v.Add("Name", model.Name);
                list.Add(v);
            }
            return new object[] { list, total, curIndex };
        }
Exemplo n.º 14
0
 void WriteAttributes(Variant attribute)
 {
     foreach (VariantItem item in attribute)
     {
         m_writer.WriteAttributeString(item.Key, item.Value.AnyCast().As<string>());
     }
 }
Exemplo n.º 15
0
        public void TestBinaryStreams()
        {
            System.Data.DataTable dt1 = new DataTable();
            dt1.Columns.Add(new DataColumn("Float", typeof(float)));
            dt1.Columns.Add(new DataColumn("Double", typeof(double)));
            dt1.Columns.Add(new DataColumn("String", typeof(string)));
            dt1.Columns.Add(new DataColumn("Boolean", typeof(bool)));
            dt1.Columns.Add(new DataColumn("Int32", typeof(int)));
            dt1.Columns.Add(new DataColumn("UInt32", typeof(uint)));
            dt1.Columns.Add(new DataColumn("Int64", typeof(long)));
            dt1.Columns.Add(new DataColumn("UInt64", typeof(ulong)));
            dt1.Columns.Add(new DataColumn("Time", typeof(TimeSpan)));
            dt1.Columns.Add(new DataColumn("DateTime", typeof(DateTime)));

            for (int i = 0; i < 10; ++i)
            {
                DataRow dr = dt1.NewRow();
                dr[0] = 1.0;
                dr[1] = 2.0;
                dr[2] = "value";
                dr[3] = true;
                dr[4] = 4;
                dr[5] = 5;
                dr[6] = 6;
                dr[7] = 7;
                dr[8] = new TimeSpan(1, 2, 3, 4, 5);
                dr[9] = new DateTime(2010, 1, 2, 3, 4, 5, 6);

                dt1.Rows.Add(dr);
            }

            Variant v1 = new Variant(dt1);

            byte[] bytes = BinaryWriter.ToBytes(v1);

            Variant v2 = BinaryReader.FromBytes(bytes);

            DataTable dt2 = v2.AsDataTable();

            Assert.AreEqual(dt1.Rows.Count, dt2.Rows.Count);
            Assert.AreEqual(dt1.Columns.Count, dt2.Columns.Count);

            for(int i=0; i<dt1.Columns.Count; ++i)
            {
                Assert.AreEqual(dt1.Columns[i].ColumnName, dt2.Columns[i].ColumnName);
                Assert.AreEqual(dt1.Columns[i].DataType, dt2.Columns[i].DataType);
            }

            Assert.AreEqual(1.0, (float)dt2.Rows[0][0]);
            Assert.AreEqual(2.0, (double)dt2.Rows[0][1]);
            Assert.AreEqual("value", (string)dt2.Rows[0][2]);
            Assert.AreEqual(true, (bool)dt2.Rows[0][3]);
            Assert.AreEqual(4, (int)dt2.Rows[0][4]);
            Assert.AreEqual(5, (uint)dt2.Rows[0][5]);
            Assert.AreEqual(6, (long)dt2.Rows[0][6]);
            Assert.AreEqual(7, (ulong)dt2.Rows[0][7]);
            Assert.AreEqual(new TimeSpan(1, 2, 3, 4, 5), (TimeSpan)dt2.Rows[0][8]);
            Assert.AreEqual(new DateTime(2010, 1, 2, 3, 4, 5, 6), (DateTime)dt2.Rows[0][9]);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 领取奖励
        /// </summary>
        /// <param name="note"></param>
        public static void BossAward(UserNote note)
        {
            string fid = note.Player.Family.Value.GetStringOrDefault("FamilyID");
            if (string.IsNullOrEmpty(fid))
            {
                note.Call(FamilyCommand.BossAwardR, false, TipManager.GetMessage(FamilyReturn.NoAddFamily));
                return;
            }

            string bid = note.GetString(0);
            var p = GameConfigAccess.Instance.FindOneById(bid);
            if (p == null)
            {
                return;
            }

            string gid = note.GetString(1); //FamilyBossAccess.Instance.ViewAward(fid + bid, note.Player.ID);
            if (string.IsNullOrEmpty(gid))
            {
                return;
            }

            string[] tt = gid.Split('$');
            int number = 1;
            if (tt.Length != 2 || (!int.TryParse(tt[1], out number)))
            {
                number = 1;
            }
            string goodsid = tt[0];

            //TODO:检查包袱
            Dictionary<string, Variant> goods = new Dictionary<string, Variant>();
            Variant tmp = new Variant();
            tmp.Add("Number1", number);
            goods.Add(goodsid, tmp);
            if (BurdenManager.GetBurdenSpace(note.Player.B0.Value.GetValue<IList>("C")) == null)
            {
                note.Call(FamilyCommand.BossAwardR, false, TipManager.GetMessage(ActivityReturn.SignAward4));
                return;
            }

            //if (BurdenManager.IsFullBurden(note.Player.B0, goods))
            //{
            //    note.Call(FamilyCommand.BossAwardR, false, TipManager.GetMessage(ActivityReturn.SignAward4));
            //    return;
            //}

            if (FamilyBossAccess.Instance.GetAward(fid + bid, note.Player.ID, gid))
            {
                //发放物品
                note.Player.AddGoods(goods, GoodsSource.FamilyBoss);
                note.Call(FamilyCommand.BossAwardR, true, gid);
            }
            else
            {
                //已领取..
                note.Call(FamilyCommand.BossAwardR, false, TipManager.GetMessage(FamilyReturn.CannotBossAward));
            }
        }
Exemplo n.º 17
0
        public ConcurrencyTest(Variant variant, string description)
            : base(variant.ToString() + ": " + description)
        {
            this.variant = variant;

            startThreadsEvent = new ManualResetEvent(false);
            endTestEvent = new ManualResetEvent(false);
        }
Exemplo n.º 18
0
 public void TestTSConstruction()
 {
     Variant v = new Variant(Variant.EnumType.TimeSeries);
     Assert.AreEqual(v.Type, Variant.EnumType.TimeSeries);
     Assert.IsTrue(v.Is(Variant.EnumType.TimeSeries));
     Assert.AreEqual(v.Count, 0);
     Assert.IsTrue(v.Empty);
 }
Exemplo n.º 19
0
 public void TestBagConstruction()
 {
     Variant v = new Variant(Variant.EnumType.Bag);
     Assert.AreEqual(v.Type, Variant.EnumType.Bag);
     Assert.IsTrue(v.Is(Variant.EnumType.Bag));
     Assert.AreEqual(v.Count, 0);
     Assert.IsTrue(v.Empty);
 }
Exemplo n.º 20
0
        /// <summary>
        /// 添加好友
        /// </summary>
        /// <param name="note"></param>
        public static void AddFriends(UserNote note)
        {
            string name = note.GetString(0);
            if (note.Player.Name == name)
            {
                return;
            }
            PlayerEx social = note.Player.Social;
            if (social == null)
            {
                note.Call(SocialCommand.AddFriendsR, false, TipManager.GetMessage(SocialReturn.UserInfoError));
                return;
            }

            PlayerBusiness player = PlayersProxy.FindPlayerByName(name);
            if (player == null)
            {
                note.Call(SocialCommand.AddFriendsR, false, TipManager.GetMessage(SocialReturn.UserInfoError));
                return;
            }

            if (social.Value != null)
            {
                if (SocialBusiness.IsLet(social, player.ID, new List<string> { "Friends" }))
                {
                    note.Call(SocialCommand.AddFriendsR, false, TipManager.GetMessage(SocialReturn.Friends));
                    return;
                }

                if (SocialBusiness.IsLet(social, player.ID, new List<string> { "Enemy" }))
                {
                    note.Call(SocialCommand.AddFriendsR, false, TipManager.GetMessage(SocialReturn.Master));
                    return;
                }
            }

            Variant v = new Variant();
            v.Add("PlayerID", player.ID);
            v.Add("Created", DateTime.UtcNow);
            IList list = social.Value.GetValue<IList>("Friends");
            int num = 0;
            if (list == null)
            {
                social.Value["Friends"] = new List<Variant>() { v };
                num = 1;
            }
            else
            {
                list.Add(v);
                num = list.Count;
            }
            social.Save();

            note.Call(SocialCommand.AddFriendsR, true, new PlayerSimple(player, 3));

            //添加好友
            note.Player.FinishNote(FinishCommand.Friends, num);
        }
Exemplo n.º 21
0
 public static string ToString(Variant value, XmlMode mode)
 {
     using (System.IO.TextWriter ms = new System.IO.StringWriter())
     {
         XmlWriter writer = new XmlWriter(ms, mode);
         writer.WriteDocument(value);
         return ms.ToString();
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// 奖励清理
 /// </summary>
 /// <returns></returns>
 public static Variant AwardClear()
 {
     Variant v = new Variant();
     foreach (int k in n_dic.Keys)
     {
         v.Add(k.ToString(), 0);
     }
     return v;
 }
Exemplo n.º 23
0
 public static LimitGoods Create(string name, Variant v)
 {
     string goodsid = v.GetStringOrDefault("GoodsID");
     if (!string.IsNullOrEmpty(goodsid))
     {
         return new LimitGoods(name, goodsid);
     }
     return null;
 }
Exemplo n.º 24
0
 public static LimitScore Create(string name, Variant v)
 {
     int score = v.GetIntOrDefault("Score");
     if (score > 0)
     {
         return new LimitScore(name, score);
     }
     return null;
 }
Exemplo n.º 25
0
 public static LimitScore Create(string name, Variant v)
 {
     int bond = v.GetIntOrDefault("Bond");
     if (bond > 0)
     {
         return new LimitScore(name, bond);
     }
     return null;
 }
Exemplo n.º 26
0
 public static LimitScore Create(string name, Variant v)
 {
     int coin = v.GetIntOrDefault("Coin");
     if (coin > 0)
     {
         return new LimitScore(name, coin);
     }
     return null;
 }
Exemplo n.º 27
0
 public static LimitMaxinto Create(string ectypeID, string name, Variant v)
 {
     int maxInto = v.GetIntOrDefault("MaxInto");
     if (maxInto > 0)
     {
         return new LimitMaxinto(ectypeID, name, maxInto);
     }
     return null;
 }
Exemplo n.º 28
0
 /// <summary>
 /// 清理完成条件
 /// </summary>
 /// <returns></returns>
 public static Variant FinishClear()
 {
     Variant v = new Variant();
     foreach (string k in m_dic.Keys)
     {
         v.Add(k, 0);
     }
     return v;
 }
Exemplo n.º 29
0
        /// <summary>
        /// 系统邮件
        /// </summary>
        public static Email SendAuctionEmail(
            Dictionary<string, object> dic,
            string type, 
            string auctionid, 
            string receiveID, 
            string receiveName,
            int Score,
            int Coin,
            List<Variant> GoodsList
            )
        {
            Email email = new Email();
            email.ID = ObjectId.GenerateNewId().ToString();
            email.Status = 0;//0表示未读取过,1已读取
            email.Ver = 1;
            email.MainType = EmailCommand.System;
            email.Created = DateTime.UtcNow;
            GameConfig gc = GameConfigAccess.Instance.FindOneById(type);
            Variant d = new Variant(16);
            string Title = gc.Value.GetStringOrDefault("Title");
            string Source = gc.Value.GetStringOrDefault("Source");
            string Content = gc.Value.GetStringOrDefault("Content");
            foreach (string k in dic.Keys)
            {
                Title = Title.Replace(k, dic[k].ToString());
                Content = Content.Replace(k, dic[k].ToString());
            }
            email.Name = Title;
            d.Add("Title", Title);
            d.Add("Source", Source);
            d.Add("Content", Content);
            d.Add("SendID", EmailCommand.System);
            d.Add("SendName", Source);
            d.Add("ReceiveID", receiveID);
            d.Add("ReceiveName", receiveName);
            //d.Add("Take", string.Empty);
            DateTime dt = DateTime.UtcNow;
            d.Add("UpdateDate", dt);
            d.Add("EndDate", dt.AddDays(30));
            d.Add("AuctionID", auctionid);
            d.Add("Score", Score);
            d.Add("Coin", Coin);
            d.Add("GoodsList", GoodsList);
            if (d.GetIntOrDefault("Score") > 0 || d.GetIntOrDefault("Coin") > 0 || (GoodsList!=null && GoodsList.Count > 0))
            {
                d.Add("IsHave", 1);
            }
            else
            {
                d.Add("IsHave", 0);
            }

            email.Value = d;
            email.Save();
            return email;
        }
Exemplo n.º 30
0
 public static LimitFamily Create(string name, Variant v)
 {
     int dayDev = v.GetIntOrDefault("DayDev");
     int familyTask = v.GetIntOrDefault("FamilyTask");
     if (familyTask > 0 || dayDev > 0)
     {
         return new LimitFamily(name, dayDev, familyTask);
     }
     return null;
 }
        public override object ChangeType(object value, Type type, CultureInfo cultureInfo)
        {
            System.Variant source = new System.Variant(value);
            if (cultureInfo == null)
            {
                cultureInfo = CultureInfo.CurrentCulture;
            }
            if (type.IsByRef)
            {
                type = type.GetElementType();
            }
            if (!type.IsPrimitive && type.IsInstanceOfType(value))
            {
                return(value);
            }
            Type type2 = value.GetType();

            if (type.IsEnum && type2.IsPrimitive)
            {
                return(Enum.Parse(type, value.ToString()));
            }
            if (type2 == typeof(DBNull))
            {
                if (type == typeof(DBNull))
                {
                    return(value);
                }
                if ((type.IsClass && type != typeof(object)) || type.IsInterface)
                {
                    return(null);
                }
            }
            object result;

            try
            {
                object obj = OAVariantLib.ChangeType(source, type, 16, cultureInfo).ToObject();
                result = obj;
            }
            catch (NotSupportedException)
            {
                throw new COMException(Environment.GetResourceString("Interop.COM_TypeMismatch"), -2147352571);
            }
            return(result);
        }
Exemplo n.º 32
0
 // Token: 0x06001592 RID: 5522 RVA: 0x0003F45B File Offset: 0x0003D65B
 internal static object MarshalHelperConvertVariantToObject(ref System.Variant v)
 {
     return(v.ToObject());
 }
Exemplo n.º 33
0
        internal static void MarshalHelperConvertObjectToVariant(object o, ref System.Variant v)
        {
            IConvertible convertible = RemotingServices.IsTransparentProxy(o) ? null : (o as IConvertible);

            if (o == null)
            {
                v = System.Variant.Empty;
                return;
            }
            if (convertible == null)
            {
                v = new System.Variant(o);
                return;
            }
            IFormatProvider invariantCulture = CultureInfo.InvariantCulture;

            switch (convertible.GetTypeCode())
            {
            case TypeCode.Empty:
                v = System.Variant.Empty;
                return;

            case TypeCode.Object:
                v = new System.Variant(o);
                return;

            case TypeCode.DBNull:
                v = System.Variant.DBNull;
                return;

            case TypeCode.Boolean:
                v = new System.Variant(convertible.ToBoolean(invariantCulture));
                return;

            case TypeCode.Char:
                v = new System.Variant(convertible.ToChar(invariantCulture));
                return;

            case TypeCode.SByte:
                v = new System.Variant(convertible.ToSByte(invariantCulture));
                return;

            case TypeCode.Byte:
                v = new System.Variant(convertible.ToByte(invariantCulture));
                return;

            case TypeCode.Int16:
                v = new System.Variant(convertible.ToInt16(invariantCulture));
                return;

            case TypeCode.UInt16:
                v = new System.Variant(convertible.ToUInt16(invariantCulture));
                return;

            case TypeCode.Int32:
                v = new System.Variant(convertible.ToInt32(invariantCulture));
                return;

            case TypeCode.UInt32:
                v = new System.Variant(convertible.ToUInt32(invariantCulture));
                return;

            case TypeCode.Int64:
                v = new System.Variant(convertible.ToInt64(invariantCulture));
                return;

            case TypeCode.UInt64:
                v = new System.Variant(convertible.ToUInt64(invariantCulture));
                return;

            case TypeCode.Single:
                v = new System.Variant(convertible.ToSingle(invariantCulture));
                return;

            case TypeCode.Double:
                v = new System.Variant(convertible.ToDouble(invariantCulture));
                return;

            case TypeCode.Decimal:
                v = new System.Variant(convertible.ToDecimal(invariantCulture));
                return;

            case TypeCode.DateTime:
                v = new System.Variant(convertible.ToDateTime(invariantCulture));
                return;

            case TypeCode.String:
                v = new System.Variant(convertible.ToString(invariantCulture));
                return;
            }
            throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", new object[]
            {
                convertible.GetTypeCode()
            }));
        }
Exemplo n.º 34
0
        internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant v)
        {
            IConvertible convertible = pValue as IConvertible;

            if (convertible != null)
            {
                IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
                switch (vt)
                {
                case 0:
                    v = Empty;
                    return;

                case 1:
                    v = DBNull;
                    return;

                case 2:
                    v = new Variant(convertible.ToInt16(invariantCulture));
                    return;

                case 3:
                    v = new Variant(convertible.ToInt32(invariantCulture));
                    return;

                case 4:
                    v = new Variant(convertible.ToSingle(invariantCulture));
                    return;

                case 5:
                    v = new Variant(convertible.ToDouble(invariantCulture));
                    return;

                case 6:
                    v = new Variant(new CurrencyWrapper(convertible.ToDecimal(invariantCulture)));
                    return;

                case 7:
                    v = new Variant(convertible.ToDateTime(invariantCulture));
                    return;

                case 8:
                    v = new Variant(convertible.ToString(invariantCulture));
                    return;

                case 9:
                    v = new Variant(new DispatchWrapper(convertible));
                    return;

                case 10:
                    v = new Variant(new ErrorWrapper(convertible.ToInt32(invariantCulture)));
                    return;

                case 11:
                    v = new Variant(convertible.ToBoolean(invariantCulture));
                    return;

                case 12:
                    v = new Variant(convertible);
                    return;

                case 13:
                    v = new Variant(new UnknownWrapper(convertible));
                    return;

                case 14:
                    v = new Variant(convertible.ToDecimal(invariantCulture));
                    return;

                case 0x10:
                    v = new Variant(convertible.ToSByte(invariantCulture));
                    return;

                case 0x11:
                    v = new Variant(convertible.ToByte(invariantCulture));
                    return;

                case 0x12:
                    v = new Variant(convertible.ToUInt16(invariantCulture));
                    return;

                case 0x13:
                    v = new Variant(convertible.ToUInt32(invariantCulture));
                    return;

                case 20:
                    v = new Variant(convertible.ToInt64(invariantCulture));
                    return;

                case 0x15:
                    v = new Variant(convertible.ToUInt64(invariantCulture));
                    return;

                case 0x16:
                    v = new Variant(convertible.ToInt32(invariantCulture));
                    return;

                case 0x17:
                    v = new Variant(convertible.ToUInt32(invariantCulture));
                    return;
                }
                throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"), new object[0]));
            }
            switch (vt)
            {
            case 8:
                if (pValue != null)
                {
                    throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"), new object[0]));
                }
                v         = new Variant(null);
                v.m_flags = 14;
                return;

            case 9:
                v = new Variant(new DispatchWrapper(pValue));
                return;

            case 12:
                v = new Variant(pValue);
                return;

            case 13:
                v = new Variant(new UnknownWrapper(pValue));
                return;

            case 0x24:
                v = new Variant(pValue);
                return;
            }
            throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"), new object[0]));
        }
Exemplo n.º 35
0
        internal static void MarshalHelperConvertObjectToVariant(object o, ref Variant v)
        {
            IConvertible convertible = RemotingServices.IsTransparentProxy(o) ? (IConvertible)null : o as IConvertible;

            if (o == null)
            {
                v = Variant.Empty;
            }
            else if (convertible == null)
            {
                v = new Variant(o);
            }
            else
            {
                IFormatProvider provider = (IFormatProvider)CultureInfo.InvariantCulture;
                switch (convertible.GetTypeCode())
                {
                case TypeCode.Empty:
                    v = Variant.Empty;
                    break;

                case TypeCode.Object:
                    v = new Variant(o);
                    break;

                case TypeCode.DBNull:
                    v = Variant.DBNull;
                    break;

                case TypeCode.Boolean:
                    v = new Variant(convertible.ToBoolean(provider));
                    break;

                case TypeCode.Char:
                    v = new Variant(convertible.ToChar(provider));
                    break;

                case TypeCode.SByte:
                    v = new Variant(convertible.ToSByte(provider));
                    break;

                case TypeCode.Byte:
                    v = new Variant(convertible.ToByte(provider));
                    break;

                case TypeCode.Int16:
                    v = new Variant(convertible.ToInt16(provider));
                    break;

                case TypeCode.UInt16:
                    v = new Variant(convertible.ToUInt16(provider));
                    break;

                case TypeCode.Int32:
                    v = new Variant(convertible.ToInt32(provider));
                    break;

                case TypeCode.UInt32:
                    v = new Variant(convertible.ToUInt32(provider));
                    break;

                case TypeCode.Int64:
                    v = new Variant(convertible.ToInt64(provider));
                    break;

                case TypeCode.UInt64:
                    v = new Variant(convertible.ToUInt64(provider));
                    break;

                case TypeCode.Single:
                    v = new Variant(convertible.ToSingle(provider));
                    break;

                case TypeCode.Double:
                    v = new Variant(convertible.ToDouble(provider));
                    break;

                case TypeCode.Decimal:
                    v = new Variant(convertible.ToDecimal(provider));
                    break;

                case TypeCode.DateTime:
                    v = new Variant(convertible.ToDateTime(provider));
                    break;

                case TypeCode.String:
                    v = new Variant((object)convertible.ToString(provider));
                    break;

                default:
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", (object)convertible.GetTypeCode()));
                }
            }
        }
Exemplo n.º 36
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static void MarshalHelperConvertObjectToVariant(Object o, ref Variant v)
        {
#if FEATURE_REMOTING
            IConvertible ic = System.Runtime.Remoting.RemotingServices.IsTransparentProxy(o) ? null : o as IConvertible;
#else
            IConvertible ic = o as IConvertible;
#endif
            if (o == null)
            {
                v = Empty;
            }
            else if (ic == null)
            {
                // This path should eventually go away. But until
                // the work is done to have all of our wrapper types implement
                // IConvertible, this is a cheapo way to get the work done.
                v = new Variant(o);
            }
            else
            {
                IFormatProvider provider = CultureInfo.InvariantCulture;
                switch (ic.GetTypeCode())
                {
                case TypeCode.Empty:
                    v = Empty;
                    break;

                case TypeCode.Object:
                    v = new Variant((Object)o);
                    break;

                case TypeCode.DBNull:
                    v = DBNull;
                    break;

                case TypeCode.Boolean:
                    v = new Variant(ic.ToBoolean(provider));
                    break;

                case TypeCode.Char:
                    v = new Variant(ic.ToChar(provider));
                    break;

                case TypeCode.SByte:
                    v = new Variant(ic.ToSByte(provider));
                    break;

                case TypeCode.Byte:
                    v = new Variant(ic.ToByte(provider));
                    break;

                case TypeCode.Int16:
                    v = new Variant(ic.ToInt16(provider));
                    break;

                case TypeCode.UInt16:
                    v = new Variant(ic.ToUInt16(provider));
                    break;

                case TypeCode.Int32:
                    v = new Variant(ic.ToInt32(provider));
                    break;

                case TypeCode.UInt32:
                    v = new Variant(ic.ToUInt32(provider));
                    break;

                case TypeCode.Int64:
                    v = new Variant(ic.ToInt64(provider));
                    break;

                case TypeCode.UInt64:
                    v = new Variant(ic.ToUInt64(provider));
                    break;

                case TypeCode.Single:
                    v = new Variant(ic.ToSingle(provider));
                    break;

                case TypeCode.Double:
                    v = new Variant(ic.ToDouble(provider));
                    break;

                case TypeCode.Decimal:
                    v = new Variant(ic.ToDecimal(provider));
                    break;

                case TypeCode.DateTime:
                    v = new Variant(ic.ToDateTime(provider));
                    break;

                case TypeCode.String:
                    v = new Variant(ic.ToString(provider));
                    break;

                default:
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", ic.GetTypeCode()));
                }
            }
        }
Exemplo n.º 37
0
        internal static void MarshalHelperCastVariant(object pValue, int vt, ref System.Variant v)
        {
            IConvertible convertible = pValue as IConvertible;

            if (convertible == null)
            {
                switch (vt)
                {
                case 8:
                    if (pValue == null)
                    {
                        v         = new System.Variant(null);
                        v.m_flags = 14;
                        return;
                    }
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));

                case 9:
                    v = new System.Variant(new DispatchWrapper(pValue));
                    return;

                case 10:
                case 11:
                    break;

                case 12:
                    v = new System.Variant(pValue);
                    return;

                case 13:
                    v = new System.Variant(new UnknownWrapper(pValue));
                    return;

                default:
                    if (vt == 36)
                    {
                        v = new System.Variant(pValue);
                        return;
                    }
                    break;
                }
                throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
            }
            IFormatProvider invariantCulture = CultureInfo.InvariantCulture;

            switch (vt)
            {
            case 0:
                v = System.Variant.Empty;
                return;

            case 1:
                v = System.Variant.DBNull;
                return;

            case 2:
                v = new System.Variant(convertible.ToInt16(invariantCulture));
                return;

            case 3:
                v = new System.Variant(convertible.ToInt32(invariantCulture));
                return;

            case 4:
                v = new System.Variant(convertible.ToSingle(invariantCulture));
                return;

            case 5:
                v = new System.Variant(convertible.ToDouble(invariantCulture));
                return;

            case 6:
                v = new System.Variant(new CurrencyWrapper(convertible.ToDecimal(invariantCulture)));
                return;

            case 7:
                v = new System.Variant(convertible.ToDateTime(invariantCulture));
                return;

            case 8:
                v = new System.Variant(convertible.ToString(invariantCulture));
                return;

            case 9:
                v = new System.Variant(new DispatchWrapper(convertible));
                return;

            case 10:
                v = new System.Variant(new ErrorWrapper(convertible.ToInt32(invariantCulture)));
                return;

            case 11:
                v = new System.Variant(convertible.ToBoolean(invariantCulture));
                return;

            case 12:
                v = new System.Variant(convertible);
                return;

            case 13:
                v = new System.Variant(new UnknownWrapper(convertible));
                return;

            case 14:
                v = new System.Variant(convertible.ToDecimal(invariantCulture));
                return;

            case 16:
                v = new System.Variant(convertible.ToSByte(invariantCulture));
                return;

            case 17:
                v = new System.Variant(convertible.ToByte(invariantCulture));
                return;

            case 18:
                v = new System.Variant(convertible.ToUInt16(invariantCulture));
                return;

            case 19:
                v = new System.Variant(convertible.ToUInt32(invariantCulture));
                return;

            case 20:
                v = new System.Variant(convertible.ToInt64(invariantCulture));
                return;

            case 21:
                v = new System.Variant(convertible.ToUInt64(invariantCulture));
                return;

            case 22:
                v = new System.Variant(convertible.ToInt32(invariantCulture));
                return;

            case 23:
                v = new System.Variant(convertible.ToUInt32(invariantCulture));
                return;
            }
            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
        }
Exemplo n.º 38
0
        internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant v)
        {
            IConvertible convertible = pValue as IConvertible;

            if (convertible == null)
            {
                switch (vt)
                {
                case 8:
                    if (pValue != null)
                    {
                        throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                    }
                    v         = new Variant((object)null);
                    v.m_flags = 14;
                    break;

                case 9:
                    v = new Variant((object)new DispatchWrapper(pValue));
                    break;

                case 12:
                    v = new Variant(pValue);
                    break;

                case 13:
                    v = new Variant((object)new UnknownWrapper(pValue));
                    break;

                case 36:
                    v = new Variant(pValue);
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
            else
            {
                IFormatProvider provider = (IFormatProvider)CultureInfo.InvariantCulture;
                switch (vt)
                {
                case 0:
                    v = Variant.Empty;
                    break;

                case 1:
                    v = Variant.DBNull;
                    break;

                case 2:
                    v = new Variant(convertible.ToInt16(provider));
                    break;

                case 3:
                    v = new Variant(convertible.ToInt32(provider));
                    break;

                case 4:
                    v = new Variant(convertible.ToSingle(provider));
                    break;

                case 5:
                    v = new Variant(convertible.ToDouble(provider));
                    break;

                case 6:
                    v = new Variant((object)new CurrencyWrapper(convertible.ToDecimal(provider)));
                    break;

                case 7:
                    v = new Variant(convertible.ToDateTime(provider));
                    break;

                case 8:
                    v = new Variant((object)convertible.ToString(provider));
                    break;

                case 9:
                    v = new Variant((object)new DispatchWrapper((object)convertible));
                    break;

                case 10:
                    v = new Variant((object)new ErrorWrapper(convertible.ToInt32(provider)));
                    break;

                case 11:
                    v = new Variant(convertible.ToBoolean(provider));
                    break;

                case 12:
                    v = new Variant((object)convertible);
                    break;

                case 13:
                    v = new Variant((object)new UnknownWrapper((object)convertible));
                    break;

                case 14:
                    v = new Variant(convertible.ToDecimal(provider));
                    break;

                case 16:
                    v = new Variant(convertible.ToSByte(provider));
                    break;

                case 17:
                    v = new Variant(convertible.ToByte(provider));
                    break;

                case 18:
                    v = new Variant(convertible.ToUInt16(provider));
                    break;

                case 19:
                    v = new Variant(convertible.ToUInt32(provider));
                    break;

                case 20:
                    v = new Variant(convertible.ToInt64(provider));
                    break;

                case 21:
                    v = new Variant(convertible.ToUInt64(provider));
                    break;

                case 22:
                    v = new Variant(convertible.ToInt32(provider));
                    break;

                case 23:
                    v = new Variant(convertible.ToUInt32(provider));
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
        }
Exemplo n.º 39
0
        // ChangeType
        // This binder uses OLEAUT to change the type of the variant.
        public override Object ChangeType(Object value, Type type, CultureInfo cultureInfo)
        {
            Variant myValue = new Variant(value);

            if (cultureInfo == null)
            {
                cultureInfo = CultureInfo.CurrentCulture;
            }

#if DISPLAY_DEBUG_INFO
            Console.WriteLine("In OleAutBinder::ChangeType converting variant of type: {0} to type: {1}", myValue.VariantType, type.Name);
#endif

            if (type.IsByRef)
            {
#if DISPLAY_DEBUG_INFO
                Console.WriteLine("Stripping byref from the type to convert to.");
#endif
                type = type.GetElementType();
            }

            // If we are trying to convert from an object to another type then we don't
            // need the OLEAUT change type, we can just use the normal COM+ mechanisms.
            if (!type.IsPrimitive && type.IsInstanceOfType(value))
            {
#if DISPLAY_DEBUG_INFO
                Console.WriteLine("Source variant can be assigned to destination type");
#endif
                return(value);
            }

            Type srcType = value.GetType();

            // Handle converting primitives to enums.
            if (type.IsEnum && srcType.IsPrimitive)
            {
#if DISPLAY_DEBUG_INFO
                Console.WriteLine("Converting primitive to enum");
#endif
                return(Enum.Parse(type, value.ToString()));
            }

            // Use the OA variant lib to convert primitive types.
            try
            {
#if DISPLAY_DEBUG_INFO
                Console.WriteLine("Using OAVariantLib.ChangeType() to do the conversion");
#endif
                // Specify the LocalBool flag to have BOOL values converted to local language rather
                // than 0 or -1.
                Object RetObj = OAVariantLib.ChangeType(myValue, type, OAVariantLib.LocalBool, cultureInfo).ToObject();

#if DISPLAY_DEBUG_INFO
                Console.WriteLine("Object returned from ChangeType is of type: " + RetObj.GetType().Name);
#endif

                return(RetObj);
            }
#if DISPLAY_DEBUG_INFO
            catch (NotSupportedException e)
#else
            catch (NotSupportedException)
#endif
            {
#if DISPLAY_DEBUG_INFO
                Console.Write("Exception thrown: ");
                Console.WriteLine(e);
#endif
                throw new COMException(SR.Interop_COM_TypeMismatch, unchecked ((int)0x80020005));
            }
        }
Exemplo n.º 40
0
        // Helper code for marshaling managed objects to VARIANT's (we use
        // managed variants as an intermediate type.
        internal static void MarshalHelperConvertObjectToVariant(object o, ref Variant v)
        {
            IConvertible ic = o as IConvertible;

            if (o == null)
            {
                v = Empty;
            }
            else if (ic == null)
            {
                // This path should eventually go away. But until
                // the work is done to have all of our wrapper types implement
                // IConvertible, this is a cheapo way to get the work done.
                v = new Variant(o);
            }
            else
            {
                IFormatProvider provider = CultureInfo.InvariantCulture;
                switch (ic.GetTypeCode())
                {
                case TypeCode.Empty:
                    v = Empty;
                    break;

                case TypeCode.Object:
                    v = new Variant((object)o);
                    break;

                case TypeCode.DBNull:
                    v = DBNull;
                    break;

                case TypeCode.Boolean:
                    v = new Variant(ic.ToBoolean(provider));
                    break;

                case TypeCode.Char:
                    v = new Variant(ic.ToChar(provider));
                    break;

                case TypeCode.SByte:
                    v = new Variant(ic.ToSByte(provider));
                    break;

                case TypeCode.Byte:
                    v = new Variant(ic.ToByte(provider));
                    break;

                case TypeCode.Int16:
                    v = new Variant(ic.ToInt16(provider));
                    break;

                case TypeCode.UInt16:
                    v = new Variant(ic.ToUInt16(provider));
                    break;

                case TypeCode.Int32:
                    v = new Variant(ic.ToInt32(provider));
                    break;

                case TypeCode.UInt32:
                    v = new Variant(ic.ToUInt32(provider));
                    break;

                case TypeCode.Int64:
                    v = new Variant(ic.ToInt64(provider));
                    break;

                case TypeCode.UInt64:
                    v = new Variant(ic.ToUInt64(provider));
                    break;

                case TypeCode.Single:
                    v = new Variant(ic.ToSingle(provider));
                    break;

                case TypeCode.Double:
                    v = new Variant(ic.ToDouble(provider));
                    break;

                case TypeCode.Decimal:
                    v = new Variant(ic.ToDecimal(provider));
                    break;

                case TypeCode.DateTime:
                    v = new Variant(ic.ToDateTime(provider));
                    break;

                case TypeCode.String:
                    v = new Variant(ic.ToString(provider));
                    break;

                default:
                    throw new NotSupportedException(SR.Format(SR.NotSupported_UnknownTypeCode, ic.GetTypeCode()));
                }
            }
        }
Exemplo n.º 41
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void MarshalHelperCastVariant(Object pValue, int vt, ref Variant v)
        {
            IConvertible iv = pValue as IConvertible;

            if (iv == null)
            {
                switch (vt)
                {
                case 9:     /*VT_DISPATCH*/
                    v = new Variant(new DispatchWrapper(pValue));
                    break;

                case 12:     /*VT_VARIANT*/
                    v = new Variant(pValue);
                    break;

                case 13:     /*VT_UNKNOWN*/
                    v = new Variant(new UnknownWrapper(pValue));
                    break;

                case 36:     /*VT_RECORD*/
                    v = new Variant(pValue);
                    break;

                case 8:     /*VT_BSTR*/
                    if (pValue == null)
                    {
                        v         = new Variant(null);
                        v.m_flags = CV_STRING;
                    }
                    else
                    {
                        throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                    }
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
            else
            {
                IFormatProvider provider = CultureInfo.InvariantCulture;
                switch (vt)
                {
                case 0:     /*VT_EMPTY*/
                    v = Empty;
                    break;

                case 1:     /*VT_NULL*/
                    v = DBNull;
                    break;

                case 2:     /*VT_I2*/
                    v = new Variant(iv.ToInt16(provider));
                    break;

                case 3:     /*VT_I4*/
                    v = new Variant(iv.ToInt32(provider));
                    break;

                case 4:     /*VT_R4*/
                    v = new Variant(iv.ToSingle(provider));
                    break;

                case 5:     /*VT_R8*/
                    v = new Variant(iv.ToDouble(provider));
                    break;

                case 6:     /*VT_CY*/
                    v = new Variant(new CurrencyWrapper(iv.ToDecimal(provider)));
                    break;

                case 7:     /*VT_DATE*/
                    v = new Variant(iv.ToDateTime(provider));
                    break;

                case 8:     /*VT_BSTR*/
                    v = new Variant(iv.ToString(provider));
                    break;

                case 9:     /*VT_DISPATCH*/
                    v = new Variant(new DispatchWrapper((Object)iv));
                    break;

                case 10:     /*VT_ERROR*/
                    v = new Variant(new ErrorWrapper(iv.ToInt32(provider)));
                    break;

                case 11:     /*VT_BOOL*/
                    v = new Variant(iv.ToBoolean(provider));
                    break;

                case 12:     /*VT_VARIANT*/
                    v = new Variant((Object)iv);
                    break;

                case 13:     /*VT_UNKNOWN*/
                    v = new Variant(new UnknownWrapper((Object)iv));
                    break;

                case 14:     /*VT_DECIMAL*/
                    v = new Variant(iv.ToDecimal(provider));
                    break;

                // case 15: /*unused*/
                //  NOT SUPPORTED

                case 16:     /*VT_I1*/
                    v = new Variant(iv.ToSByte(provider));
                    break;

                case 17:     /*VT_UI1*/
                    v = new Variant(iv.ToByte(provider));
                    break;

                case 18:     /*VT_UI2*/
                    v = new Variant(iv.ToUInt16(provider));
                    break;

                case 19:     /*VT_UI4*/
                    v = new Variant(iv.ToUInt32(provider));
                    break;

                case 20:     /*VT_I8*/
                    v = new Variant(iv.ToInt64(provider));
                    break;

                case 21:     /*VT_UI8*/
                    v = new Variant(iv.ToUInt64(provider));
                    break;

                case 22:     /*VT_INT*/
                    v = new Variant(iv.ToInt32(provider));
                    break;

                case 23:     /*VT_UINT*/
                    v = new Variant(iv.ToUInt32(provider));
                    break;

                default:
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
            }
        }