本文整理汇总了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);
}
示例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();
}
示例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 });
}
示例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);
}
示例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]);
}
示例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();
}
}