本文整理汇总了C#中ParameterCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterCollection.Remove方法的具体用法?C# ParameterCollection.Remove怎么用?C# ParameterCollection.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterCollection
的用法示例。
在下文中一共展示了ParameterCollection.Remove方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverrideRemoveTest
public void OverrideRemoveTest()
{
var parameters = new ParameterCollection();
parameters.Add(new Parameter("a", 1));
parameters["a"] = 2;
parameters.Remove("a");
Assert.AreEqual(0, parameters.Collection.Count());
}
示例2: Test1
public void Test1()
{
var container1 = new ParameterCollection("container1");
var container2 = new ParameterCollection("container2");
var container3 = new ParameterCollection("container3");
var container4 = new ParameterCollection("container4");
#pragma warning disable 612 // for ParameterPath and ParameterListener
var path = new ParameterPath(PropertyContainer, PropertyContainer, PropertyContainer, PropertyFloat);
var listener = new ParameterListener(container1, path);
#pragma warning restore 612
int updateCounter = 0;
object currentValue = null;
listener.ParameterUpdated += (container, path2, newValue) => { updateCounter++; currentValue = newValue; };
container1.Set(PropertyContainer, container2);
container2.Set(PropertyContainer, container2);
Assert.AreEqual(0, updateCounter);
Assert.AreEqual(null, currentValue);
// New value should have been detected (through cycle)
container2.Set(PropertyFloat, 32.0f);
Assert.AreEqual(1, updateCounter);
Assert.AreEqual(32.0f, currentValue);
// Setting it again should not trigger anything
container2.Set(PropertyFloat, 32.0f);
Assert.AreEqual(1, updateCounter);
// Value should be resetted (because container3 doesn't point on any value)
container2.Set(PropertyContainer, container3);
Assert.AreEqual(2, updateCounter);
Assert.AreEqual(null, currentValue);
// New value should come from container3->container4
container3.Set(PropertyContainer, container4);
container4.Set(PropertyFloat, 48.0f);
Assert.AreEqual(3, updateCounter);
Assert.AreEqual(48.0f, currentValue);
// Value should be again the one from container2
container2.Set(PropertyContainer, container2);
Assert.AreEqual(4, updateCounter);
Assert.AreEqual(32.0f, currentValue);
// Value should be resetted
container2.Remove(PropertyFloat);
Assert.AreEqual(5, updateCounter);
Assert.AreEqual(null, currentValue);
container1.Remove(PropertyContainer);
Assert.AreEqual(5, updateCounter);
Assert.AreEqual(null, currentValue);
}
示例3: EnableFixedAmbientLight
public static void EnableFixedAmbientLight(ParameterCollection parameters, bool enable)
{
if (parameters == null) throw new ArgumentNullException("parameters");
if (enable)
{
parameters.Set(EnvironmentLights, DefaultAmbientLighting);
}
else
{
parameters.Remove(EnvironmentLights);
}
}
示例4: TestCollections1
public void TestCollections1()
{
//
// => Initialize
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | P = 3,3,3 | (Root2)
// | V = 2,2,2 | | |
// --------------- ---------------
//
// ---------------
// | | (Child)
// | |
// ---------------
var root1Collection = new ParameterCollection("Root1");
var root2Collection = new ParameterCollection("Root2");
var childCollection = new ParameterCollection("Child");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
root1Collection.Set(paramP, new Vector3(1, 1, 1));
root1Collection.Set(paramV, new Vector3(2, 2, 2));
root2Collection.Set(paramP, new Vector3(3, 3, 3));
//
// => Add source Roo1 and Root2 to Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | P = 3,3,3 | (Root2)
// | V = 2,2,2 | | |
// --------------- ---------------
// | /
// --------------- /
// | P = ^,^,^ | (Child) /
// | V = ^,^,^ |
// ---------------
// P = 3,3,3
// V = 2,2,2
childCollection.AddSources(root1Collection, root2Collection);
Assert.AreEqual(childCollection.Count, 2);
Assert.AreEqual(childCollection.Get(paramP), new Vector3(3, 3, 3));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Add source Roo1 and Root2 to Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | | (Root2)
// | V = 2,2,2 | | V = 3,3,3 |
// --------------- ---------------
// | /
// --------------- /
// | P = ^,^,^ | (Child) /
// | V = ^,^,^ |
// ---------------
// P = 1,1,1
// V = 3,3,3
root2Collection.Remove(paramP);
root2Collection.Set(paramV, new Vector3(3,3,3));
Assert.AreEqual(childCollection.Count, 2);
Assert.AreEqual(childCollection.Get(paramP), new Vector3(1, 1, 1));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
//
// => Remove source Root1 for Child
//
// --------------- ---------------
// | P = 1,1,1 | (Root1) | | (Root2)
// | V = 2,2,2 | | V = 3,3,3 |
// --------------- ---------------
// /
// --------------- /
// | | (Child) /
// | V = ^,^,^ |
// ---------------
// V = 3,3,3
childCollection.RemoveSource(root1Collection);
Assert.AreEqual(childCollection.Count, 1);
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
//
// => Inherit Root1 from Child
//
// --------------- ---------------
// | | (Child) ------| | (Root2)
// | V = ^,^,^ | | V = 3,3,3 |
// --------------- ---------------
// |
// ---------------
// | P = 1,1,1 | (Root1)
// | V = 2,2,2 |
// ---------------
root1Collection.AddSources(childCollection);
Assert.AreEqual(root1Collection.Count, 2);
Assert.AreEqual(root1Collection.Get(paramP), new Vector3(1, 1, 1));
Assert.AreEqual(root1Collection.Get(paramV), new Vector3(2, 2, 2));
}
示例5: TestCollectionsBasicValues
public void TestCollectionsBasicValues()
{
//
// => Initialize
//
// ---------------
// | | (Root)
// | |
// ---------------
// |
// ---------------
// | | (Child)
// | |
// ---------------
var rootCollection = new ParameterCollection("Root");
var childCollection = new ParameterCollection("Child");
childCollection.AddSources(rootCollection);
//
// => Set P and V on Root (1,1,1)
//
// ---------------
// | V = 1,1,1 | (Root)
// | P = 1,1,1 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// | P = ^,^,^ |
// ---------------
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
rootCollection.Set(paramV, new Vector3(1, 1, 1));
rootCollection.Set(paramP, new Vector3(1, 1, 1));
// Verify collection.Count
Assert.AreEqual(childCollection.Count, 2);
// Verify collection.Contains
Assert.AreEqual(childCollection.ContainsKey(paramV), true);
Assert.AreEqual(childCollection.ContainsKey(paramP), true);
//
// => Set V in Root, Get from Child
//
// ---------------
// | V = 2,2,2 | (Root)
// | P = 1,1,1 |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// | P = ^,^,^ |
// ---------------
// Verify the Get and returned value
Assert.AreEqual(childCollection.Get(paramV), new Vector3(1, 1, 1));
rootCollection.Set(paramV, new Vector3(2,2,2));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Remove P from Root
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// ---------------
rootCollection.Remove(paramP);
Assert.AreEqual(childCollection.Count, 1);
//
// => Overrides V in Child (3,3,3)
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = 3,3,3 | (Child)
// ---------------
childCollection.Set(paramV, new Vector3(3, 3, 3));
Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
Assert.AreEqual(rootCollection.Get(paramV), new Vector3(2, 2, 2));
//
// => Reset Key V on Child
//
// ---------------
// | V = 2,2,2 | (Root)
// | |
// ---------------
// |
// ---------------
// | V = ^,^,^ | (Child)
// ---------------
childCollection.Reset(paramV);
//.........这里部分代码省略.........
示例6: TestBasicValues
public void TestBasicValues()
{
//
// => Initialize, Set V (1,1,1)
//
// ---------------
// | V = 1,1,1 | (Test)
// | |
// ---------------
var collection = new ParameterCollection("Test");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
collection.Set(paramV, new Vector3(1, 1, 1));
// Verify collection.Count
Assert.AreEqual(collection.Count, 1);
// Verify collection.Contains
Assert.AreEqual(collection.ContainsKey(paramV), true);
// Verify collection.Keys Enumerator
int count = 0;
foreach(var key in collection.Keys)
{
Assert.AreEqual(key, paramV);
count++;
}
Assert.AreEqual(count, 1);
// Verify the Get and returned value
var value = collection.Get(paramV);
Assert.AreEqual(value, new Vector3(1,1,1));
//
// => Set P (2,2,2)
//
// ---------------
// | V = 1,1,1 | (Test)
// | P = 2,2,2 |
// ---------------
collection.Set(paramP, new Vector3(2,2,2));
Assert.AreEqual(collection.Count, 2);
Assert.AreEqual(collection.Get(paramP), new Vector3(2, 2, 2));
//
// => Remove param V
//
// ---------------
// | | (Test)
// | P = 2,2,2 |
// ---------------
collection.Remove(paramV);
Assert.AreEqual(collection.Count, 1);
// Check that param
Assert.AreEqual(collection.Get(paramP), new Vector3(2, 2, 2));
//
// => Remove param P
//
// ---------------
// | | (Test)
// | |
// ---------------
collection.Remove(paramP);
Assert.AreEqual(collection.Count, 0);
//
// => Set param V
//
// ---------------
// | V = 2,2,2 | (Test)
// | |
// ---------------
// Just add same key to test that everything is going fine
collection.Set(paramV, new Vector3(2, 2, 2));
Assert.AreEqual(collection.Count, 1);
Assert.AreEqual(collection.Get(paramV), new Vector3(2, 2, 2));
}
示例7: TestDynamicArrayValues1
public void TestDynamicArrayValues1()
{
//
// => Initialize, set V and P
//
// -------------------------------
// | VArray = {1,2,3} | (Test)
// | PArray = {0,1,0} |
// -------------------------------
var collection = new ParameterCollection("Test");
var paramVArray = new ParameterKey<float[]>("VArray",3);
var paramPArray = new ParameterKey<float[]>("PArray",3);
// Set paramV and paramP
collection.SetArray(paramVArray, new float[] { 1, 2, 3 });
collection.SetArray(paramPArray, new float[] { 0, 1, 0 });
//
// => Set VDyn1 and VDyn2
//
// -------------------------------
// | VArray = {1,2,3} | (Test)
// | PArray = {0,1,0} |
// | VPDynArray = VArray+PArray |
// -------------------------------
var paramVPDynArray = new ParameterKey<float[]>("VPDynArray", 3);
// paramViewProjDyn2 = paramV - paramP
collection.AddDynamic(paramVPDynArray, ParameterDynamicValue.New(paramVArray, paramPArray,
(ref float[] paramVArg, ref float[] paramPArg, ref float[] output) =>
{
for (int i = 0; i < 3; i++)
output[i] = paramVArg[i] + paramPArg[i];
}));
float[] result;
collection.Get(paramVPDynArray, out result);
Assert.AreEqual(new Vector3(result), new Vector3(1, 3, 3));
// Remove value from array
collection.Remove(paramVPDynArray);
}
示例8: TestDynamicValues3
public void TestDynamicValues3()
{
//
// => Initialize, set V and P
//
// ------------------------
// | V = 1,2,3 | (Test)
// | P = 0,1,0 |
// ------------------------
var collection = new ParameterCollection("Test");
var paramV = new ParameterKey<Vector3>("View");
var paramP = new ParameterKey<Vector3>("Proj");
// Set paramV and paramP
collection.Set(paramV, new Vector3(1, 2, 3));
collection.Set(paramP, new Vector3(0, 1, 0));
//
// => Set VDyn1 and VDyn2
//
// ------------------------
// | V = 1,2,3 | (Test)
// | P = 0,1,0 |
// | VDyn1 = V + P |
// | VDyn2 = V - P |
// ------------------------
// VDyn1 = (1,3,3)
// VDyn2 = (1,1,3)
var paramViewProjDyn1 = new ParameterKey<Vector3>("ViewProjDyn1");
var paramViewProjDyn2 = new ParameterKey<Vector3>("ViewProjDyn2");
var valueViewProjDyn1 = ParameterDynamicValue.New(paramV, paramP, (ref Vector3 paramVArg, ref Vector3 paramPArg, ref Vector3 output) => output = paramVArg + paramPArg);
collection.AddDynamic(paramViewProjDyn1, valueViewProjDyn1);
// paramViewProjDyn2 = paramV - paramP
collection.AddDynamic(paramViewProjDyn2, ParameterDynamicValue.New(paramP, paramV, (ref Vector3 paramPArg, ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg - paramPArg));
Assert.AreEqual(collection.Get(paramViewProjDyn1), new Vector3(1, 3, 3));
Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 1, 3));
//
// => Set VDyn1 and VDyn2
//
// ------------------------
// | V = 1,2,3 | (Test)
// | P = 0,1,0 |
// | VDyn1 = V + P |
// | VDyn2 = V + P |
// ------------------------
// VDyn1 = (1,3,3)
// VDyn2 = (1,3,3)
collection.AddDynamic(paramViewProjDyn2, valueViewProjDyn1);
Assert.AreEqual(collection.Get(paramViewProjDyn2), new Vector3(1, 3, 3));
//
// => Remove all variables
//
// ------------------------
// | | (Test)
// | |
// ------------------------
collection.Remove(paramViewProjDyn1);
collection.Remove(paramViewProjDyn2);
collection.Remove(paramV);
collection.Remove(paramP);
Assert.AreEqual(collection.Count, 0);
}
示例9: TestDynamicValues2
public void TestDynamicValues2()
{
//
// => Initialize
//
// ------------------------
// | V = 1,2,3 | (Test)
// | VDyn = V + (1,1,1) |
// ------------------------
// VDyn = (2,3,4)
var collection = new ParameterCollection("Test");
var paramV = new ParameterKey<Vector3>("View");
var paramViewDyn = new ParameterKey<Vector3>("ViewDyn");
// Set paramV and paramViewDyn1
collection.Set(paramV, new Vector3(1,2,3));
collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(1, 1, 1)));
// Check that value is correctly updated
Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(2, 3, 4));
//
// => Set V to (3, 2, 1)
//
// ------------------------
// | V = 3,2,1 | (Test)
// | VDyn = V + (1,1,1) |
// ------------------------
// VDyn = (4,3,2)
collection.Set(paramV, new Vector3(3, 2, 1));
Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(4, 3, 2));
//
// => Set VDyn = V + (2,2,2)
//
// ------------------------
// | V = 3,2,1 | (Test)
// | VDyn = V + (2,2,2) |
// ------------------------
// VDyn = (5,4,3)
collection.AddDynamic(paramViewDyn, ParameterDynamicValue.New(paramV, (ref Vector3 paramVArg, ref Vector3 output) => output = paramVArg + new Vector3(2, 2, 2)));
Assert.AreEqual(collection.Get(paramViewDyn), new Vector3(5, 4, 3));
// Should throw an InvalidOperationException, as paramV is used by paramViewDyn and
// cannot be removed
//Assert.Throws(typeof(InvalidOperationException), () => collection.Remove(paramV));
// Remove all variables
collection.Remove(paramViewDyn);
collection.Remove(paramV);
//
// => Remove V and VDyn
//
// ------------------------
// | | (Test)
// | |
// ------------------------
Assert.AreEqual(collection.Count, 0);
}
示例10: CollectionManagerCollatesParameterEvents
public void CollectionManagerCollatesParameterEvents()
{
ParameterCollection collection = new ParameterCollection();
Parameter descriptor = null;
int expectedcollectionValidationCount = 6;
Action collectionValidationAction = () =>
{
expectedcollectionValidationCount--;
if (expectedcollectionValidationCount < 0)
{
Assert.Fail("Too many collection validation action invocations.");
}
};
this.CollectionManagerCollatesTemplate(
(validationAction) =>
{
return new ParameterCollectionManager(collection, p => validationAction(), pc => collectionValidationAction());
},
() =>
{
collection.Add(new Parameter());
},
() =>
{
collection[0].ParameterName = "First";
},
() =>
{
collection.Add(new Parameter());
},
() =>
{
collection[1].ParameterName = "Second";
},
() =>
{
collection[1] = new Parameter();
},
() =>
{
descriptor = collection[0];
collection.Remove(descriptor);
},
() =>
{
descriptor.ParameterName = "Removed";
});
Assert.AreEqual(0, expectedcollectionValidationCount,
"Collection validation count should be 0.");
}