本文整理汇总了C#中BsonInt32类的典型用法代码示例。如果您正苦于以下问题:C# BsonInt32类的具体用法?C# BsonInt32怎么用?C# BsonInt32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonInt32类属于命名空间,在下文中一共展示了BsonInt32类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: getValue
/// <summary>
/// 使用属性会发生一些MONO上的移植问题
/// </summary>
/// <returns></returns>
public BsonValue getValue()
{
BsonValue mValue = null;
switch (cmbDataType.SelectedIndex)
{
case 0:
mValue = new BsonString(txtBsonValue.Text);
break;
case 1:
mValue = new BsonInt32(Convert.ToInt32(NumberPick.Value));
break;
case 2:
mValue = new BsonDateTime(dateTimePicker.Value);
break;
case 3:
if (radTrue.Checked)
{
mValue = BsonBoolean.True;
}
else
{
mValue = BsonBoolean.False;
}
break;
case 4:
mValue = mBsonArray;
break;
case 5:
mValue = mBsonDocument;
break;
}
return mValue;
}
开发者ID:huchao007,项目名称:MagicMongoDBTool,代码行数:37,代码来源:ctlBsonValue.cs
示例2: TestSetDocumentIdBsonValue
public void TestSetDocumentIdBsonValue()
{
var document = new BsonDocument { { "x", "abc" } };
var id = new BsonInt32(1);
((IBsonIdProvider)BsonDocumentSerializer.Instance).SetDocumentId(document, id);
Assert.IsTrue(document["_id"].IsInt32);
Assert.AreEqual(1, document["_id"].AsInt32);
}
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:8,代码来源:CSharp446Tests.cs
示例3: CompareTo_BsonDouble_should_return_expected_result
public void CompareTo_BsonDouble_should_return_expected_result(int int32Value, double otherDoubleValue, int expectedResult)
{
var subject = new BsonInt32(int32Value);
var other = new BsonDouble(otherDoubleValue);
var result = subject.CompareTo(other);
result.Should().Be(expectedResult);
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonInt32Tests.cs
示例4: CompareTo_BsonInt32_should_return_expected_result
public void CompareTo_BsonInt32_should_return_expected_result(long int64Value, int otherInt32Value, int expectedResult)
{
var subject = new BsonInt64(int64Value);
var other = new BsonInt32(otherInt32Value);
var result = subject.CompareTo(other);
result.Should().Be(expectedResult);
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonInt64Tests.cs
示例5: TestCompareOneAndTwo
public void TestCompareOneAndTwo()
{
var n1 = new BsonInt32(1);
var n2 = new BsonInt32(2);
Assert.IsTrue(n1 < n2);
Assert.IsTrue(n1 <= n2);
Assert.IsTrue(n1 != n2);
Assert.IsFalse(n1 == n2);
Assert.IsFalse(n1 > n2);
Assert.IsFalse(n1 >= n2);
}
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:11,代码来源:BsonValueCompareToTests.cs
示例6: CompareTo_BsonInt32_should_return_expected_result
public void CompareTo_BsonInt32_should_return_expected_result(int int32Value, int otherInt32Value, int expectedResult)
{
var subject = new BsonInt32(int32Value);
var other = new BsonInt32(otherInt32Value);
var result1 = subject.CompareTo((BsonInt32)other);
var result2 = subject.CompareTo((BsonValue)other);
result1.Should().Be(expectedResult);
result2.Should().Be(expectedResult);
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:11,代码来源:BsonInt32Tests.cs
示例7: TestCompareDifferentTypeOnes
public void TestCompareDifferentTypeOnes()
{
var n1 = new BsonInt32(1);
var n2 = new BsonInt64(1);
var n3 = new BsonDouble(1.0);
Assert.IsTrue(n1 == n2);
Assert.IsTrue(n1 == n3);
Assert.IsTrue(n2 == n1);
Assert.IsTrue(n2 == n3);
Assert.IsTrue(n3 == n1);
Assert.IsTrue(n3 == n2);
}
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:12,代码来源:BsonValueCompareToTests.cs
示例8: TestCompareDifferentTypeOnes
public void TestCompareDifferentTypeOnes()
{
var n1 = new BsonInt32(1);
var n2 = new BsonInt64(1);
var n3 = new BsonDouble(1.0);
Assert.IsTrue(n1 == n2);
Assert.IsTrue(n1 == n3);
Assert.IsTrue(n2 == n1);
Assert.IsTrue(n2 == n3);
Assert.IsTrue(n3 == n1);
Assert.IsTrue(n3 == n2);
var v1 = (BsonValue)new BsonInt32(1);
var v2 = (BsonValue)new BsonInt64(1);
var v3 = (BsonValue)new BsonDouble(1.0);
Assert.IsTrue(v1 == v2);
Assert.IsTrue(v1 == v3);
Assert.IsTrue(v2 == v1);
Assert.IsTrue(v2 == v3);
Assert.IsTrue(v3 == v1);
Assert.IsTrue(v3 == v2);
}
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:22,代码来源:BsonValueCompareToTests.cs
示例9: TestBsonInt32
public void TestBsonInt32()
{
var value = new BsonInt32(1);
Assert.AreSame(value, ((IConvertible)value).ToType(typeof(object), null));
Assert.AreEqual(true, Convert.ToBoolean(value));
Assert.AreEqual(1, Convert.ToByte(value));
Assert.AreEqual(1, Convert.ToChar(value));
Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(value));
Assert.AreEqual(1m, Convert.ToDecimal(value));
Assert.AreEqual(1.0, Convert.ToDouble(value));
Assert.AreEqual(1, Convert.ToInt16(value));
Assert.AreEqual(1, Convert.ToInt32(value));
Assert.AreEqual(1, Convert.ToInt64(value));
Assert.AreEqual(1, Convert.ToSByte(value));
Assert.AreEqual(1.0F, Convert.ToSingle(value));
Assert.AreEqual("1", Convert.ToString(value));
Assert.AreEqual(1, Convert.ToUInt16(value));
Assert.AreEqual(1, Convert.ToUInt32(value));
Assert.AreEqual(1, Convert.ToUInt64(value));
}
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:20,代码来源:BsonValueIConvertibleTests.cs
示例10: GetValue
/// <summary>
/// 使用属性会发生一些MONO上的移植问题
/// </summary>
/// <returns></returns>
public BsonValue GetValue(BsonValueEx.BasicType DataType)
{
BsonValue mValue = null;
switch (DataType)
{
case BsonValueEx.BasicType.BsonString:
mValue = new BsonString(txtBsonValue.Text);
break;
case BsonValueEx.BasicType.BsonInt32:
mValue = new BsonInt32(Convert.ToInt32(NumberPick.Value));
break;
case BsonValueEx.BasicType.BsonInt64:
mValue = new BsonInt64(Convert.ToInt64(NumberPick.Value));
break;
case BsonValueEx.BasicType.BsonDecimal128:
mValue = new BsonDecimal128(Convert.ToDecimal(NumberPick.Value));
break;
case BsonValueEx.BasicType.BsonDouble:
mValue = new BsonDouble(Convert.ToDouble(txtBsonValue.Text));
break;
case BsonValueEx.BasicType.BsonDateTime:
mValue = new BsonDateTime(dateTimePicker.Value);
break;
case BsonValueEx.BasicType.BsonBoolean:
mValue = radTrue.Checked ? BsonBoolean.True : BsonBoolean.False;
break;
case BsonValueEx.BasicType.BsonArray:
case BsonValueEx.BasicType.BsonLegacyPoint:
mValue = _mBsonArray;
break;
case BsonValueEx.BasicType.BsonGeoJSON:
case BsonValueEx.BasicType.BsonDocument:
mValue = _mBsonDocument;
break;
case BsonValueEx.BasicType.BsonMaxKey:
mValue = BsonMaxKey.Value;
break;
case BsonValueEx.BasicType.BsonMinKey:
mValue = BsonMinKey.Value;
break;
case BsonValueEx.BasicType.BsonBinary:
mValue = new BsonBinaryData(Encoding.Default.GetBytes(txtBsonValue.Text));
break;
}
return mValue;
}
开发者ID:magicdict,项目名称:MongoCola,代码行数:50,代码来源:ctlBsonValue.cs
示例11: EquivalentToIntegerNotMatch
public void EquivalentToIntegerNotMatch()
{
BsonValue val1 = new BsonInt32(42);
BsonValue val2 = new BsonInt32(-42);
Assert.IsFalse(val1.EquivalentTo(val2));
}
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:6,代码来源:BsonValueExtensionsTests.cs
示例12: TestIsNumeric
public void TestIsNumeric()
{
BsonValue d128 = new BsonDecimal128(1.0M);
BsonValue d = new BsonDouble(1.0);
BsonValue i32 = new BsonInt32(1);
BsonValue i64 = new BsonInt64(1L);
BsonValue s = new BsonString("");
Assert.True(d128.IsNumeric);
Assert.True(d.IsNumeric);
Assert.True(i32.IsNumeric);
Assert.True(i64.IsNumeric);
Assert.False(s.IsDecimal128);
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonValueTests.cs
示例13: GetBsonValue
/// <summary>
/// 还原BsonValue
/// </summary>
/// <returns></returns>
public BsonValue GetBsonValue()
{
BsonValue value = new BsonString(string.Empty);
switch (MBsonType)
{
case "BsonString":
value = new BsonString(MBsonString);
break;
case "BsonInt32":
value = new BsonInt32(MBsonInt32);
break;
case "BsonDateTime":
value = new BsonDateTime(MBsonDateTime);
break;
case "BsonBoolean":
value = MBsonBoolean ? BsonBoolean.True : BsonBoolean.False;
break;
case "BsonDouble":
value = new BsonDouble(MBsonDouble);
break;
}
return value;
}
开发者ID:1287516153,项目名称:MongoCola,代码行数:27,代码来源:BsonValueEx.cs
示例14: DiffTwoDifferentBsonTypes
public void DiffTwoDifferentBsonTypes()
{
// Arrange
var a = new BsonInt32(100);
var b = new BsonInt64(100);
var expected = new BsonDocument("types differ", new BsonDocument {{"a", "Int32"}, {"b", "Int64"}});
// Act
var doc = a.Diff(b);
// Assert
Assert.That(doc, Is.EqualTo(expected));
}
开发者ID:jvanzella,项目名称:ch-bson,代码行数:13,代码来源:Diff.cs
示例15: TestClass
public TestClass(
BsonInt32 value
)
{
this.B = value;
this.V = value;
}
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonValueSerializerTests.cs
示例16: TestCompareTwoOnes
public void TestCompareTwoOnes()
{
var n1 = new BsonInt32(1);
var n2 = new BsonInt32(1);
Assert.False(n1 < n2);
Assert.True(n1 <= n2);
Assert.False(n1 != n2);
Assert.True(n1 == n2);
Assert.False(n1 > n2);
Assert.True(n1 >= n2);
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:BsonValueCompareToTests.cs
示例17: TryInt32
/// <summary>Try to convert the string to a <see cref="BsonInt32"/>.</summary>
/// <param name="value">The value to convert.</param>
/// <param name="bsonValue">The BsonValue result.</param>
/// <returns><c>true</c> if the value was converted; otherwise <c>false</c>.</returns>
public static bool TryInt32(this string value, out BsonValue bsonValue)
{
bsonValue = null;
if (value == null)
return false;
int result;
var r = int.TryParse(value, out result);
if (r) bsonValue = new BsonInt32(result);
return r;
}
开发者ID:PerryPal,项目名称:NLog.Mongo,代码行数:16,代码来源:MongoConvert.cs
示例18: GetCustomFieldData
/// <summary>
/// Gets the data for one custom field, and any relevant GUIDs.
/// </summary>
/// <param name="hvo">Hvo of object we're getting the field for.</param>
/// <param name="flid">Flid for this field.</param>
/// <param name="fieldSourceType">Either "entry", "senses" or "examples". Could also be "allomorphs", eventually.</param>
/// <param name="bsonForThisField">Output of a BsonDocument with the following structure: <br />
/// { fieldName: { "value": BsonValue, "guid": "some-guid-as-a-string" } } <br />
/// -OR- <br />
/// { fieldName: { "value": BsonValue, "guid": ["guid1", "guid2", "guid3"] } } <br />
/// The format of the fieldName key will be "customField_FOO_field_name_with_underscores",
/// where FOO is one of "entry", "senses", or "examples". <br />
/// The type of the "guid" value (array or string) will determine whether there is a single GUID,
/// or a list of GUIDs that happens to contain only one entry.
/// If there is no "guid" key, that field has no need for a GUID. (E.g., a number).
/// </param>
/// <param name="listConverters">Dictionary of ConvertFdoToMongoOptionList instances, keyed by list code</param>
/// <param name="customFieldType">output string of LF custom field type</param>
private void GetCustomFieldData(int hvo, int flid, string fieldSourceType,
IDictionary<string, ConvertFdoToMongoOptionList> listConverters,
out BsonDocument bsonForThisField, out string customFieldType)
{
bsonForThisField = null;
customFieldType = string.Empty;
BsonValue fieldValue = null;
BsonValue fieldGuid = null; // Might be a single value, might be a list (as a BsonArray)
ISilDataAccessManaged data = (ISilDataAccessManaged)cache.DomainDataByFlid;
CellarPropertyType fdoFieldType = (CellarPropertyType)fdoMetaData.GetFieldType(flid);
var dataGuids = new List<Guid>();
// Valid field types in FDO are GenDate, Integer, String, OwningAtomic, ReferenceAtomic, and ReferenceCollection, so that's all we implement.
switch (fdoFieldType)
{
case CellarPropertyType.GenDate:
GenDate genDate = data.get_GenDateProp(hvo, flid);
string genDateStr = genDate.ToLongString();
// LF wants single-string fields in the format { "ws": { "value": "contents" } }
fieldValue = String.IsNullOrEmpty(genDateStr) ? null :
LfMultiText.FromSingleStringMapping(
MagicStrings.LanguageCodeForGenDateFields, genDateStr).AsBsonDocument();
break;
// When parsing, will use GenDate.TryParse(str, out genDate)
case CellarPropertyType.Integer:
fieldValue = new BsonInt32(data.get_IntProp(hvo, flid));
if (fieldValue.AsInt32 == default(Int32))
fieldValue = null; // Suppress int fields with 0 in them, to save Mongo DB space
else
// LF wants single-string fields in the format { "ws": { "value": "contents" } }
fieldValue = LfMultiText.FromSingleStringMapping(
MagicStrings.LanguageCodeForIntFields, fieldValue.AsInt32.ToString()).AsBsonDocument();
break;
case CellarPropertyType.OwningAtomic:
case CellarPropertyType.ReferenceAtomic:
int ownedHvo = data.get_ObjectProp(hvo, flid);
fieldValue = GetCustomReferencedObject(ownedHvo, flid, listConverters, ref dataGuids);
if (fieldValue != null && fdoFieldType == CellarPropertyType.ReferenceAtomic)
{
// Single CmPossiblity reference - LF expects format like { "value": "key of possibility" }
fieldValue = new BsonDocument("value", fieldValue);
}
fieldGuid = new BsonString(dataGuids.FirstOrDefault().ToString());
break;
case CellarPropertyType.MultiUnicode:
ITsMultiString tss = data.get_MultiStringProp(hvo, flid);
if (tss != null && tss.StringCount > 0)
fieldValue = LfMultiText.FromMultiITsString(tss, cache.ServiceLocator.WritingSystemManager).AsBsonDocument();
break;
case CellarPropertyType.OwningCollection:
case CellarPropertyType.OwningSequence:
case CellarPropertyType.ReferenceCollection:
case CellarPropertyType.ReferenceSequence:
int[] listHvos = data.VecProp(hvo, flid);
var innerValues = new BsonArray(listHvos.Select(listHvo => GetCustomReferencedObject(listHvo, flid, listConverters, ref dataGuids)).Where(x => x != null));
if (innerValues.Count == 0)
fieldValue = null;
else
{
fieldValue = new BsonDocument("values", innerValues);
fieldGuid = new BsonArray(dataGuids.Select(guid => guid.ToString()));
}
break;
case CellarPropertyType.String:
ITsString iTsValue = data.get_StringProp(hvo, flid);
if (iTsValue == null || String.IsNullOrEmpty(iTsValue.Text))
fieldValue = null;
else
fieldValue = LfMultiText.FromSingleITsString(iTsValue, cache.ServiceLocator.WritingSystemManager).AsBsonDocument();
break;
default:
fieldValue = null;
if (logger != null)
logger.Warning("FDO CellarPropertyType.{0} not recognized for LF custom field", fdoFieldType.ToString());
break;
}
CellarPropertyTypeToLfCustomFieldType.TryGetValue(fdoFieldType, out customFieldType);
if (fieldValue == null)
//.........这里部分代码省略.........
开发者ID:ermshiperete,项目名称:LfMerge,代码行数:101,代码来源:ConvertFdoToMongoCustomField.cs
示例19: TestCompareToBsonValue
public void TestCompareToBsonValue()
{
var other = new BsonInt32(1);
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
var result = wrapper.CompareTo(other);
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(1, result);
}
开发者ID:rakesh-elevate,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonDocumentWrapperTests.cs
示例20: GetBsonValue
/// <summary>
/// 还原BsonValue
/// </summary>
/// <returns></returns>
public BsonValue GetBsonValue()
{
BsonValue Value = new BsonString("");
switch (mBsonType)
{
case "BsonString":
Value = new BsonString(mBsonString);
break;
case "BsonInt32":
Value = new BsonInt32(mBsonInt32);
break;
case "BsonDateTime":
Value = new BsonDateTime(mBsonDateTime);
break;
case "BsonBoolean":
if (mBsonBoolean)
{
Value = BsonBoolean.True;
}
else
{
Value = BsonBoolean.False;
}
break;
default:
break;
}
return Value;
}
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:33,代码来源:BsonValueEx.cs
注:本文中的BsonInt32类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论