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


C# Variable.Clone方法代码示例

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


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

示例1: Clone

        public void Clone()
        {
            var x = new Variable<int>("x")
                {
                    Values = {1, 2, 3},
                    Unit = new Unit("distance", "m"),
                    ExtrapolationType = ExtrapolationType.Constant,
                    InterpolationType = InterpolationType.Linear
                };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
            Assert.AreNotSame(x.Unit, clone.Unit);
            Assert.AreEqual(x.Unit.Name, clone.Unit.Name);
            Assert.AreEqual(x.Unit.Symbol, clone.Unit.Symbol);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:25,代码来源:VariableTest.cs

示例2: Add

        public void Add(Variable var)
        {
            if(var == null)
            {
                throw new ParseException("Valid  variable", "null variable");
            }

            if(var.Name == null)
            {
                throw new ParseException("Valid  variable", "null named variable");
            }

            if(var.Name.Length == 0)
            {
                throw new ParseException("Valid variable", "non named variable");
            }

            if(!VarIsArray(var))
            {
                if((var as VariableItem).Value.Type == HVMType.Unknown)
                {
                    throw new ParseException("Variable of known type",
                        string.Format("Variable of unknown type: {0}", var.Name));
                }
            }

            if(_symbols.ContainsKey(var.Name))
            {
                throw new ParseException("Unique variable", string.Format("Variable added to lexical scope twice: {0}", var.Name));
            }

            _symbols[var.Name]=var.Clone();
        }
开发者ID:bubbafat,项目名称:HVM,代码行数:33,代码来源:LexicalScope.cs

示例3: CloneUsingStore

        public void CloneUsingStore()
        {
            var x = new Variable<int>("x") { Values = { 1, 2, 3 } };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:14,代码来源:VariableTest.cs

示例4: Clone

        public void Clone()
        {
            var x = new Variable<int>("x") { Values = {1, 2, 3} };
            x.ExtrapolationType = ApproximationType.Constant;
            x.InterpolationType = ApproximationType.Linear;

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)
            
            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] {1, 2, 3});
            Assert.AreEqual(x.ExtrapolationType,clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:19,代码来源:VariableTest.cs

示例5: CloneDependentVariable

        public void CloneDependentVariable()
        {
            var x = new Variable<int>("x") {Values = {1, 2, 3}};
            var y = new Variable<int>("y") {Arguments = {x}};

            // TODO: would be nice to call above as: var y = = new Variable<int>("y") { Arguments = { x } };
            
            var clonedY = (IVariable<int>)y.Clone();

            // check argument
            Assert.AreEqual(y.Name, clonedY.Name);
            Assert.AreNotEqual(y, clonedY);
            Assert.AreNotEqual(y.Store, clonedY.Store);
            Assert.AreEqual(y.Values.Count, clonedY.Values.Count);

            // check argument
            var clonedX = (IVariable<int>)clonedY.Arguments[0];
            Assert.AreEqual(x.Name, clonedX.Name);
            Assert.AreNotEqual(x, clonedX);
            Assert.AreNotEqual(x.Store, clonedX.Store);
            Assert.AreEqual(x.Values.Count, clonedX.Values.Count);
            Assert.IsTrue(x.Values.SequenceEqual(clonedX.Values));
            Assert.AreEqual(y.Arguments[0].Values[0],clonedY.Arguments[0].Values[0]);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:24,代码来源:VariableTest.cs

示例6: Update

        public void Update(Variable var)
        {
            if(var == null)
            {
                throw new ParseException("Valid  variable", "null variable");
            }

            if(var.Name == null)
            {
                throw new ParseException("Valid  variable", "null named variable");
            }

            if(var.Name.Length == 0)
            {
                throw new ParseException("Valid variable", "non named variable");
            }

            if(var.Type == HVMType.Unknown)
            {
                throw new ParseException("Variable of known type",
                    string.Format("Variable of unknown type: {0}", var.Name));
            }

            LexicalScope ls = GetContainingLexicalScope(var.Name);
            if(ls != null)
            {
                ls._symbols[var.Name]=var.Clone();
            }
        }
开发者ID:bubbafat,项目名称:HVM,代码行数:29,代码来源:LexicalScope.cs


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