当前位置: 首页>>代码示例>>C#>>正文


C# BsonValue.ToUniversalTime方法代码示例

本文整理汇总了C#中BsonValue.ToUniversalTime方法的典型用法代码示例。如果您正苦于以下问题:C# BsonValue.ToUniversalTime方法的具体用法?C# BsonValue.ToUniversalTime怎么用?C# BsonValue.ToUniversalTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonValue的用法示例。


在下文中一共展示了BsonValue.ToUniversalTime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BsonValueEx

 /// <summary>
 ///     初始化
 /// </summary>
 /// <param name="value"></param>
 public BsonValueEx(BsonValue value)
 {
     if (value.IsString)
     {
         MBsonType = "BsonString";
         MBsonString = value.ToString();
     }
     if (value.IsInt32)
     {
         MBsonType = "BsonInt32";
         MBsonInt32 = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         MBsonType = "BsonDateTime";
         MBsonDateTime = value.ToUniversalTime();
     }
     if (value.IsBoolean)
     {
         MBsonType = "BsonBoolean";
         MBsonBoolean = value.AsBoolean;
     }
     if (value.IsDouble)
     {
         MBsonType = "BsonDouble";
         MBsonDouble = value.AsDouble;
     }
 }
开发者ID:1287516153,项目名称:MongoCola,代码行数:32,代码来源:BsonValueEx.cs

示例2: SetValue

        public void SetValue(string name, BsonValue value)
        {
            object dotNetObject;

            switch(value.BsonType)
            {
                case BsonType.Int32: dotNetObject = value.AsInt32; break;
                case BsonType.Int64: dotNetObject = value.AsInt64; break;
                case BsonType.String: dotNetObject = value.AsString; break;
                case BsonType.Double: dotNetObject = value.AsDouble; break;
                case BsonType.Boolean: dotNetObject = value.AsBoolean; break;
                case BsonType.DateTime: dotNetObject = value.ToUniversalTime(); break;
                case BsonType.Null: dotNetObject = null; break;
                default: throw new NotSupportedException(string.Format("the bson type [{0}] is not supported", value.BsonType));
            }

            _values.Add(name, dotNetObject);
        }
开发者ID:dream-365,项目名称:lemon,代码行数:18,代码来源:SqlValueSetter.cs

示例3: MapToDotNetValue

        /// <summary>
        /// Maps a BsonValue to a .NET value.
        /// </summary>
        /// <param name="bsonValue">The BsonValue.</param>
        /// <param name="options">The BsonTypeMapperOptions.</param>
        /// <returns>The mapped .NET value.</returns>
        public static object MapToDotNetValue(BsonValue bsonValue, BsonTypeMapperOptions options)
        {
            switch (bsonValue.BsonType)
            {
                case BsonType.Array:
                    var bsonArray = (BsonArray)bsonValue;
                    if (options.MapBsonArrayTo == typeof(BsonArray))
                    {
                        return bsonArray;
                    }
                    else if (options.MapBsonArrayTo == typeof(object[]))
                    {
                        var array = new object[bsonArray.Count];
                        for (int i = 0; i < bsonArray.Count; i++)
                        {
                            array[i] = MapToDotNetValue(bsonArray[i], options);
                        }
                        return array;
                    }
                    else if (typeof(IList<object>).IsAssignableFrom(options.MapBsonArrayTo))
                    {
                        var list = (IList<object>)Activator.CreateInstance(options.MapBsonArrayTo);
                        for (int i = 0; i < bsonArray.Count; i++)
                        {
                            list.Add(MapToDotNetValue(bsonArray[i], options));
                        }
                        return list;
                    }
                    else if (typeof(IList).IsAssignableFrom(options.MapBsonArrayTo))
                    {
                        var list = (IList)Activator.CreateInstance(options.MapBsonArrayTo);
                        for (int i = 0; i < bsonArray.Count; i++)
                        {
                            list.Add(MapToDotNetValue(bsonArray[i], options));
                        }
                        return list;
                    }
                    else
                    {
                        var message = string.Format("A BsonArray can't be mapped to a {0}.", BsonUtils.GetFriendlyTypeName(options.MapBsonArrayTo));
                        throw new NotSupportedException(message);
                    }
                case BsonType.Binary:
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
                    var bsonBinaryData = (BsonBinaryData)bsonValue;
                    if (bsonBinaryData.SubType == BsonBinarySubType.Binary ||
                        bsonBinaryData.SubType == BsonBinarySubType.OldBinary && options.MapOldBinaryToByteArray)
                    {
                        return bsonBinaryData.Bytes;
                    }
                    else if (bsonBinaryData.SubType == BsonBinarySubType.UuidLegacy || bsonBinaryData.SubType == BsonBinarySubType.UuidStandard)
                    {
                        return bsonBinaryData.ToGuid();
                    }
                    else
                    {
                        return bsonBinaryData; // unmapped
                    }
#pragma warning restore 618
                case BsonType.Boolean:
                    return bsonValue.AsBoolean;
                case BsonType.DateTime:
                    return bsonValue.ToUniversalTime();
                case BsonType.Document:
                    var bsonDocument = (BsonDocument)bsonValue;
                    if (options.MapBsonDocumentTo == typeof(BsonDocument))
                    {
                        return bsonDocument;
                    }
                    else if (typeof(IDictionary<string, object>).IsAssignableFrom(options.MapBsonDocumentTo))
                    {
                        var dictionary = (IDictionary<string, object>)Activator.CreateInstance(options.MapBsonDocumentTo);
                        foreach (var element in bsonDocument.Elements)
                        {
                            var mappedValue = MapToDotNetValue(element.Value, options);
                            if (dictionary.ContainsKey(element.Name))
                            {
                                switch (options.DuplicateNameHandling)
                                {
                                    case DuplicateNameHandling.Ignore:
                                        break;
                                    case DuplicateNameHandling.Overwrite:
                                    default:
                                        dictionary[element.Name] = mappedValue;
                                        break;
                                    case DuplicateNameHandling.ThrowException:
                                        var message = string.Format("Duplicate element name '{0}'.", element.Name);
                                        throw new ArgumentOutOfRangeException(message);
                                }
                            }
                            else
                            {
                                dictionary.Add(element.Name, mappedValue);
                            }
//.........这里部分代码省略.........
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:101,代码来源:BsonTypeMapper.cs

示例4: SetValue

        /// <summary>
        ///     使用属性会发生一些MONO上的移植问题
        /// </summary>
        /// <returns></returns>
        public void SetValue(BsonValue value, BsonValueEx.BasicType DataType = BsonValueEx.BasicType.BsonUndefined)
        {
            txtBsonValue.Visible = false;
            txtBsonValue.Text = string.Empty;
            txtBsonValue.ReadOnly = false;
            radTrue.Visible = false;
            radFalse.Visible = false;
            radFalse.Checked = true;
            dateTimePicker.Visible = false;
            NumberPick.Visible = false;

            if (value.IsString)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text = value.ToString();
            }

            if (value.IsInt32)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsInt32;
            }

            if (value.IsInt64)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsInt64;
            }

            if (value.IsDecimal128)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsDecimal;
            }

            if (value.IsDouble)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text = value.AsDouble.ToString();
            }

            if (value.IsValidDateTime)
            {
                dateTimePicker.Visible = true;
                dateTimePicker.Value = value.ToUniversalTime();
            }

            if (value.IsBsonMaxKey || value.IsBsonMinKey)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Enabled = false;
                txtBsonValue.Text = value.ToString();
            }

            if (value.IsBoolean)
            {
                radTrue.Visible = true;
                radFalse.Visible = true;
                if (value.AsBoolean)
                {
                    radTrue.Checked = true;
                }
                else
                {
                    radFalse.Checked = true;
                }
            }
            if (value.IsBsonArray)
            {
                if (GetArray == null)
                {
                    MessageBox.Show("GetArray委托不存在!");
                    return;
                }
                if (DataType == BsonValueEx.BasicType.BsonLegacyPoint)
                {
                    //地理
                    var t = GetGeoPoint();
                    if (t != null)
                    {
                        _mBsonArray = t;
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
                else
                {
                    //普通数组
                    var t = GetArray();
                    if (t != null)
                    {
                        _mBsonArray = t;
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
//.........这里部分代码省略.........
开发者ID:magicdict,项目名称:MongoCola,代码行数:101,代码来源:ctlBsonValue.cs

示例5: setValue

 /// <summary>
 /// 使用属性会发生一些MONO上的移植问题
 /// </summary>
 /// <returns></returns>
 public void setValue(BsonValue value)
 {
     txtBsonValue.Visible = false;
     txtBsonValue.Text = String.Empty;
     txtBsonValue.ReadOnly = false;
     radTrue.Visible = false;
     radFalse.Visible = false;
     radFalse.Checked = true;
     dateTimePicker.Visible = false;
     NumberPick.Visible = false;
     if (value.IsString)
     {
         cmbDataType.SelectedIndex = 0;
         txtBsonValue.Visible = true;
         txtBsonValue.Text = value.ToString();
     }
     if (value.IsInt32)
     {
         cmbDataType.SelectedIndex = 1;
         NumberPick.Visible = true;
         NumberPick.Value = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         dateTimePicker.Visible = true;
         dateTimePicker.Value = value.ToUniversalTime();
         cmbDataType.SelectedIndex = 2;
     }
     if (value.IsBoolean)
     {
         radTrue.Visible = true;
         radFalse.Visible = true;
         if (value.AsBoolean)
         {
             radTrue.Checked = true;
         }
         else
         {
             radFalse.Checked = true;
         }
         cmbDataType.SelectedIndex = 3;
     }
     if (value.IsBsonArray)
     {
         frmArrayCreator frmInsertArray = new frmArrayCreator();
         SystemManager.OpenForm(frmInsertArray, false, true);
         if (frmInsertArray.mBsonArray != null)
         {
             mBsonArray = frmInsertArray.mBsonArray;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = mBsonArray.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 4;
         }
     }
     if (value.IsBsonDocument)
     {
         frmNewDocument frmInsertDoc = new frmNewDocument();
         SystemManager.OpenForm(frmInsertDoc, false, true);
         if (frmInsertDoc.mBsonDocument != null)
         {
             mBsonDocument = frmInsertDoc.mBsonDocument;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = mBsonDocument.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 5;
         }
     }
 }
开发者ID:huchao007,项目名称:MagicMongoDBTool,代码行数:73,代码来源:ctlBsonValue.cs

示例6: SetValue

 /// <summary>
 ///     使用属性会发生一些MONO上的移植问题
 /// </summary>
 /// <returns></returns>
 public void SetValue(BsonValue value)
 {
     txtBsonValue.Visible = false;
     txtBsonValue.Text = string.Empty;
     txtBsonValue.ReadOnly = false;
     radTrue.Visible = false;
     radFalse.Visible = false;
     radFalse.Checked = true;
     dateTimePicker.Visible = false;
     NumberPick.Visible = false;
     if (value.IsString)
     {
         cmbDataType.SelectedIndex = 0;
         txtBsonValue.Visible = true;
         txtBsonValue.Text = value.ToString();
     }
     if (value.IsInt32)
     {
         cmbDataType.SelectedIndex = 1;
         NumberPick.Visible = true;
         NumberPick.Value = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         dateTimePicker.Visible = true;
         dateTimePicker.Value = value.ToUniversalTime();
         cmbDataType.SelectedIndex = 2;
     }
     if (value.IsBoolean)
     {
         radTrue.Visible = true;
         radFalse.Visible = true;
         if (value.AsBoolean)
         {
             radTrue.Checked = true;
         }
         else
         {
             radFalse.Checked = true;
         }
         cmbDataType.SelectedIndex = 3;
     }
     if (value.IsBsonArray)
     {
         var t = GetArray();
         if (t != null)
         {
             _mBsonArray = t;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = _mBsonArray.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 4;
         }
     }
     if (value.IsBsonDocument)
     {
         var t = GetDocument();
         if (t != null)
         {
             _mBsonDocument = t;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = _mBsonDocument.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 5;
         }
     }
 }
开发者ID:lizhi5753186,项目名称:MongoCola,代码行数:71,代码来源:ctlBsonValue.cs

示例7: ConvertToString

        /// <summary>
        /// BsonValue转展示用字符
        /// </summary>
        /// <param name="bsonValue"></param>
        /// <returns></returns>
        public static String ConvertToString(BsonValue bsonValue)
        {
            //二进制数据
            if (bsonValue.IsBsonBinaryData)
            {
                return "[Binary]";
            }
            //空值
            if (bsonValue.IsBsonNull)
            {
                return "[Empty]";
            }
            //文档
            if (bsonValue.IsBsonDocument)
            {
                return bsonValue.ToString() + "[Contains" + bsonValue.ToBsonDocument().ElementCount + "Documents]";
            }
            //时间
            if (bsonValue.IsBsonDateTime)
            {
                DateTime bsonData = bsonValue.ToUniversalTime();
                //@flydreamer提出的本地化时间要求
                return bsonData.ToLocalTime().ToString();
            }

            //字符
            if (bsonValue.IsString)
            {
                //只有在字符的时候加上""
                return "\"" + bsonValue.ToString() + "\"";
            }

            //其他
            return bsonValue.ToString();
        }
开发者ID:huchao007,项目名称:MagicMongoDBTool,代码行数:40,代码来源:MongoDBHelper_View.cs

示例8: BsonValueEx

        /// <summary>
        ///     初始化
        /// </summary>
        /// <param name="value"></param>
        public BsonValueEx(BsonValue value)
        {
            if (value.IsString)
            {
                mBsonType = BasicType.BsonString;
                mBsonString = value.ToString();
            }

            if (value.IsInt32)
            {
                mBsonType = BasicType.BsonInt32;
                mBsonInt32 = value.AsInt32;
            }
            if (value.IsInt64)
            {
                mBsonType = BasicType.BsonInt64;
                mBsonInt64 = value.AsInt64;
            }

            if (value.IsDecimal128)
            {
                mBsonType = BasicType.BsonDecimal128;
                mBSonDecimal128 = value.AsDecimal;
            }
            if (value.IsDouble)
            {
                mBsonType = BasicType.BsonDouble;
                mBsonDouble = value.AsDouble;
            }

            if (value.IsValidDateTime)
            {
                mBsonType = BasicType.BsonDateTime;
                mBsonDateTime = value.ToUniversalTime();
            }
            if (value.IsBoolean)
            {
                mBsonType = BasicType.BsonBoolean;
                mBsonBoolean = value.AsBoolean;
            }

            if (value.IsBsonMaxKey)
            {
                mBsonType = BasicType.BsonMaxKey;
            }
            if (value.IsBsonMinKey)
            {
                mBsonType = BasicType.BsonMinKey;
            }

            if (value.IsBsonBinaryData)
            {
                mBsonType = BasicType.BsonBinary;
                mBsonBinary = value.AsBsonBinaryData.Bytes;
            }
        }
开发者ID:magicdict,项目名称:MongoCola,代码行数:60,代码来源:BsonValueEx.cs


注:本文中的BsonValue.ToUniversalTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。