本文整理汇总了C#中System.Collections类的典型用法代码示例。如果您正苦于以下问题:C# System.Collections类的具体用法?C# System.Collections怎么用?C# System.Collections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Collections类属于命名空间,在下文中一共展示了System.Collections类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
var instanceType = node.Object == null ? null : node.Object.Type;
var map = new[] { new { Param = instanceType, Arg = node.Object } }.ToList();
map.AddRange(node.Method.GetParameters()
.Zip(node.Arguments, (p, a) => new { Param = p.ParameterType, Arg = a }));
// for any local collection parameters in the method, make a
// replacement argument which will print its elements
var replacements = (map.Where(x => x.Param != null && x.Param.IsGenericType)
.Select(x => new {x, g = x.Param.GetGenericTypeDefinition()})
.Where(@t => @t.g == typeof (IEnumerable<>) || @t.g == typeof (List<>))
.Where(@t => @t.x.Arg.NodeType == ExpressionType.Constant)
.Select(@t => new {@t, elementType = @t.x.Param.GetGenericArguments().Single()})
.Select(
@t =>
new
{
@[email protected],
Replacement =
Expression.Constant("{" + string.Join("|", (IEnumerable) ((ConstantExpression) @[email protected]).Value) + "}")
})).ToList();
if (replacements.Any())
{
var args = map.Select(x => (from r in replacements
where r.Arg == x.Arg
select r.Replacement).SingleOrDefault() ?? x.Arg).ToList();
node = node.Update(args.First(), args.Skip(1));
}
return base.VisitMethodCall(node);
}
示例2: FilePathMatcherTest
public void FilePathMatcherTest()
{
string[] testFiles = new [] {"c:/temp/subfolder/file.js",
"c:/temp/file.cs",
"c:/projects/temp/file.cs",
"c:/projects/file.js",
"c:/projects/file.min.js"};
List<string> matches = new List<string>(FilePathMatcher.MatchFiles("*.js",testFiles,false));
List<string> expected = new List<string>(new[] {"c:/temp/subfolder/file.js", "c:/projects/file.js",
"c:/projects/file.min.js"});
Assert.AreEqual(3,matches.Count,"Matches single extension pattern *.js");
Assert.AreEqual(string.Join(",", expected),string.Join(",",matches),"List matches");
matches = new List<string>(FilePathMatcher.MatchFiles("*.min.js",testFiles,true));
Assert.AreEqual(4,matches.Count,"Matches exclusion pattern *.min.js");
matches = new List<string>(FilePathMatcher.MatchFiles("temp/",testFiles,true));
expected = new List<string>(new[] {"c:/projects/file.js",
"c:/projects/file.min.js"});
Assert.AreEqual(string.Join(",",expected),string.Join(",",matches),"List matches on excluding a folder path");
}
示例3: MultipleExtensionsTest
public void MultipleExtensionsTest(string url, string match, string pathInfo)
{
string[] files = new[] { "~/1.one", "~/2.two", "~/1.1/2/3.3", "~/one/two/3/4.4", "~/one/two/3/4/5/6/foo.htm" };
string[] extensions = new[] { "aspx", "hao", "one", "two", "3", "4" };
ConstraintTest(files, extensions, url, match, pathInfo);
}
示例4: ToList
private static IList<object> ToList(object obj)
{
var list = new List<object>();
if (obj == null)
{
return list;
}
var types = new[]
{
typeof(string), typeof(ObjectId),
typeof(Commit), typeof(TagAnnotation),
typeof(Tag), typeof(Branch), typeof(DetachedHead),
typeof(Reference), typeof(DirectReference), typeof(SymbolicReference)
};
if (types.Contains(obj.GetType()))
{
list.Add(obj);
return list;
}
list.AddRange(((IEnumerable)obj).Cast<object>());
return list;
}
示例5: test_flatten_strings
public void test_flatten_strings()
{
var a1 = new[] { "1", "2", "3" };
var a2 = new[] { "5", "6" };
var a3 = new object[] { "4", a2 };
var a4 = new object[] { a1, a3 };
assert_equal(new[] { "1", "2", "3", "4", "5", "6" }, a4.Flatten());
assert_equal(new object[] { a1, a3 }, a4);
var a5 = new object[] { a1, new object[0], a3 };
assert_equal(new object[] { "1", "2", "3", "4", "5", "6" }, a5.Flatten());
assert_equal(new object[0], new object[0].Flatten());
assert_equal(new object[0],
new object[] { new object[] { new object[] { new object[] { }, new object[] { } }, new object[] { new object[] { } }, new object[] { } }, new object[] { new object[] { new object[] { } } } }.Flatten());
var a8 = new object[] { new object[] { "1", "2" }, "3" };
var a9 = a8.Flatten(0);
assert_equal(a8, a9);
assert_equal(new object[] { "abc" },
new object[] { new object[] { new string[0] }, new[] { "abc" } }.Flatten());
assert_equal(new object[] { "abc" },
new object[] { new[] { "abc" }, new object[] { new string[0] } }.Flatten());
}
示例6: CreatePlayer
//プレイヤーを生成させるコルーチン関数
IEnumerator CreatePlayer()
{
Vector3 pos = new Vector3(Random.Range (-20.0f,20.0f),0.0f,(-20.0f,20.0f));
//ネットワーク上のプレイヤーを動的に生成
Network.Instantiate(player,pos,Quaternion.identity,0);
yield return null;
}
示例7: EvalReturnsSimplePropertyValue
public void EvalReturnsSimplePropertyValue()
{
var obj = new { Foo = "Bar" };
ViewDataDictionary vdd = new ViewDataDictionary(obj);
Assert.Equal("Bar", vdd.Eval("Foo"));
}
示例8: OrderedSetIsInOrder
public void OrderedSetIsInOrder()
{
var names = new[] {"First B", "Second B"};
const int TheId = 100;
var a = new A {Name = "First", Id = TheId};
var b = new B {Name = names[1], OrderBy = 3, AId = TheId};
a.Items.Add(b);
var b2 = new B {Name = names[0], OrderBy = 1, AId = TheId};
a.Items.Add(b2);
ISession s = OpenSession();
s.Save(a);
s.Flush();
s.Close();
s = OpenSession();
var newA = s.Get<A>(a.Id);
Assert.AreEqual(2, newA.Items.Count);
int counter = 0;
foreach (B item in newA.Items)
{
Assert.AreEqual(names[counter], item.Name);
counter++;
}
s.Close();
}
示例9: FillBackwardThenForwardTest
public void FillBackwardThenForwardTest()
{
var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN });
sp.ReplaceNanFill(FillDirection.Backward).ReplaceNanFill(FillDirection.Forward);
var expected = new[] { 1f, 1f, 2f, 2f, 2f };
CollectionAssert.AreEqual(expected, sp.Prices);
}
示例10: ExecuteAsync_Returns_CorrectResponse
public void ExecuteAsync_Returns_CorrectResponse()
{
// Arrange
AuthenticationHeaderValue expectedChallenge1 = CreateChallenge();
AuthenticationHeaderValue expectedChallenge2 = CreateChallenge();
IEnumerable<AuthenticationHeaderValue> challenges = new[] { expectedChallenge1, expectedChallenge2 };
using (HttpRequestMessage expectedRequest = CreateRequest())
{
IHttpActionResult result = CreateProductUnderTest(challenges, expectedRequest);
// Act
Task<HttpResponseMessage> task = result.ExecuteAsync(CancellationToken.None);
// Assert
Assert.NotNull(task);
task.WaitUntilCompleted();
using (HttpResponseMessage response = task.Result)
{
Assert.NotNull(response);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Equal(2, response.Headers.WwwAuthenticate.Count);
Assert.Same(expectedChallenge1, response.Headers.WwwAuthenticate.ElementAt(0));
Assert.Same(expectedChallenge2, response.Headers.WwwAuthenticate.ElementAt(1));
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Same(expectedRequest, response.RequestMessage);
}
}
}
示例11: ShouldCompareIntegerArraysAsDifferent
public void ShouldCompareIntegerArraysAsDifferent()
{
var first = new[] { 1, 2, 3 };
var second = new[] { 1, 4, 3 };
Assert.That(first.CollectionEqual(second), Is.False, "Thought different integer arrays was equal");
}
示例12: CanResolveObjectAndType
public void CanResolveObjectAndType()
{
var lines = new[] {"object VifPackage: TVifPackage", "end"};
var vif = new VifObjectBuilder().Build(lines);
Assert.AreEqual("VifPackage", vif.Name);
Assert.AreEqual("TVifPackage", vif.Clazz);
}
示例13: ShouldCompareIntegerArraysAsEqual
public void ShouldCompareIntegerArraysAsEqual()
{
var first = new[] { 1, 2, 3 };
var second = new[] { 1, 2, 3 };
Assert.That(first.CollectionEqual(second), Is.True, "Thought equal integer arrays wasn't equal");
}
示例14: UpdateMesh
void UpdateMesh()
{
Vector3[] vertices = new [] {
new Vector3( 0f, 0f, 0f ),
new Vector3( width, 0f, 0f ),
new Vector3( 0f, height, 0f ),
new Vector3( width, height, 0f )
};
int[] triangles = new [] {
0, 2, 1,
2, 3, 1
};
Vector3[] normals = new [] {
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward
};
Vector2[] uv = new [] {
new Vector2( 0, 0 ),
new Vector2( 1, 0 ),
new Vector2( 0, 1 ),
new Vector2( 1, 1 )
};
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.normals = normals;
mesh.uv = uv;
}
示例15: CastWithFrom
public void CastWithFrom()
{
IEnumerable strings = new[] { "first", "second", "third" };
var query = from string x in strings
select x;
query.AssertSequenceEqual("first", "second", "third");
}