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


C# Variant.AsObject方法代码示例

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


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

示例1: TestConstruction

        public void TestConstruction()
        {
            TestObject1 obj1 = new TestObject1("some value");

            Variant v1 = new Variant(obj1);
            Assert.AreEqual(v1.Type, Variant.EnumType.Object);

            TestObject1 obj2 = v1.AsObject<TestObject1>();
            Assert.AreEqual(obj1, obj2);

            Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); });
            Assert.Throws<VariantException>(delegate { v1.AsObject<VariantObjectProxy>(); });

            VariantObjectProxy obj3 = new VariantObjectProxy(obj1.Class);
            obj3.Inflate(obj2.Deflate(), obj2.Version);

            Assert.AreEqual(obj3.Class, "TestObject1");
            Assert.AreEqual(obj3.Version, 1);
            Assert.AreEqual(obj3.Deflate().Type, Variant.EnumType.Dictionary);

            Variant v2 = new Variant(obj3);

            Assert.IsInstanceOf<VariantObjectProxy>(v2.AsObject());

            Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); });

            TestObject1 obj5 = v2.AsObject<TestObject1>();
            Assert.AreEqual(obj5.Class, "TestObject1");
            Assert.AreEqual(obj5.Version, 1);

            Assert.IsInstanceOf<TestObject1>(v2.AsObject());
        }
开发者ID:proteanic,项目名称:protean,代码行数:32,代码来源:TestObject.cs

示例2: WriteVariant


//.........这里部分代码省略.........
                        else if (v >= 0 && v < byte.MaxValue)
                        {
                            _writer.Write((byte)EncodingKind.Int32_1Byte);
                            _writer.Write((byte)v);
                        }
                        else if (v >= 0 && v < ushort.MaxValue)
                        {
                            _writer.Write((byte)EncodingKind.Int32_2Bytes);
                            _writer.Write((ushort)v);
                        }
                        else
                        {
                            _writer.Write((byte)EncodingKind.Int32);
                            _writer.Write(v);
                        }
                    }
                    break;

                case VariantKind.UInt32:
                    {
                        var v = value.AsUInt32();
                        if (v >= 0 && v <= 10)
                        {
                            _writer.Write((byte)((int)EncodingKind.UInt32_0 + v));
                        }
                        else if (v >= 0 && v < byte.MaxValue)
                        {
                            _writer.Write((byte)EncodingKind.UInt32_1Byte);
                            _writer.Write((byte)v);
                        }
                        else if (v >= 0 && v < ushort.MaxValue)
                        {
                            _writer.Write((byte)EncodingKind.UInt32_2Bytes);
                            _writer.Write((ushort)v);
                        }
                        else
                        {
                            _writer.Write((byte)EncodingKind.UInt32);
                            _writer.Write(v);
                        }
                    }
                    break;

                case VariantKind.Int64:
                    _writer.Write((byte)EncodingKind.Int64);
                    _writer.Write(value.AsInt64());
                    break;

                case VariantKind.UInt64:
                    _writer.Write((byte)EncodingKind.UInt64);
                    _writer.Write(value.AsUInt64());
                    break;

                case VariantKind.Decimal:
                    _writer.Write((byte)EncodingKind.Decimal);
                    _writer.Write(value.AsDecimal());
                    break;

                case VariantKind.Float4:
                    _writer.Write((byte)EncodingKind.Float4);
                    _writer.Write(value.AsSingle());
                    break;

                case VariantKind.Float8:
                    _writer.Write((byte)EncodingKind.Float8);
                    _writer.Write(value.AsDouble());
                    break;

                case VariantKind.Char:
                    _writer.Write((byte)EncodingKind.Char);
                    _writer.Write((ushort)value.AsChar());  // written as ushort because BinaryWriter fails on chars that are unicode surrogates
                    break;

                case VariantKind.String:
                    WriteStringValue(value.AsString());
                    break;

                case VariantKind.BoxedEnum:
                    var e = value.AsBoxedEnum();
                    WriteBoxedEnum(e, e.GetType());
                    break;

                case VariantKind.DateTime:
                    _writer.Write((byte)EncodingKind.DateTime);
                    _writer.Write(value.AsDateTime().ToBinary());
                    break;

                case VariantKind.Type:
                    WriteType(value.AsType());
                    break;

                case VariantKind.Array:
                    WriteArray(value.AsArray());
                    break;

                case VariantKind.Object:
                    WriteObject(value.AsObject());
                    break;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:101,代码来源:StreamObjectWriter.cs


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