本文整理汇总了C#中System.Collections类的典型用法代码示例。如果您正苦于以下问题:C# System.Collections类的具体用法?C# System.Collections怎么用?C# System.Collections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Collections类属于命名空间,在下文中一共展示了System.Collections类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:david0718,项目名称:LinqCache,代码行数:35,代码来源:LocalCollectionExpander.cs
示例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");
}
开发者ID:garethowen,项目名称:SharpLinter,代码行数:26,代码来源:UtilityUnitTests.cs
示例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);
}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:7,代码来源:WebPageRouteTest.cs
示例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;
}
开发者ID:Ran-QUAN,项目名称:libgit2sharp,代码行数:26,代码来源:CommitFilter.cs
示例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());
}
开发者ID:wastaz,项目名称:with,代码行数:25,代码来源:FlattenTests.cs
示例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;
}
开发者ID:Monma8,项目名称:ShooterNet0702,代码行数:8,代码来源:NetworkMgr.cs
示例7: EvalReturnsSimplePropertyValue
public void EvalReturnsSimplePropertyValue()
{
var obj = new { Foo = "Bar" };
ViewDataDictionary vdd = new ViewDataDictionary(obj);
Assert.Equal("Bar", vdd.Eval("Foo"));
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:7,代码来源:ViewDataDictionaryTest.cs
示例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();
}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:30,代码来源:OrderedSetFixture.cs
示例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);
}
开发者ID:miguelqvd,项目名称:QSTK.Net,代码行数:7,代码来源:FillNanTests.cs
示例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);
}
}
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:30,代码来源:UnauthorizedResultTests.cs
示例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");
}
开发者ID:rogernorling,项目名称:csharp-utilities,代码行数:7,代码来源:CollectionEqualTest.cs
示例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);
}
开发者ID:1pindsvin,项目名称:yagni,代码行数:7,代码来源:VifRegExFixture.cs
示例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");
}
开发者ID:rogernorling,项目名称:csharp-utilities,代码行数:7,代码来源:CollectionEqualTest.cs
示例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;
}
开发者ID:brulo,项目名称:the_pantry,代码行数:33,代码来源:GenerateMesh.cs
示例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");
}
开发者ID:mafm,项目名称:edulinq,代码行数:7,代码来源:QueryExpressionTest.cs
示例16: EvalWithModelAndDictionaryPropertyEvaluatesDictionaryValue
public void EvalWithModelAndDictionaryPropertyEvaluatesDictionaryValue()
{
var obj = new { Foo = new Dictionary<string, object> { { "Bar", "Baz" } } };
ViewDataDictionary vdd = new ViewDataDictionary(obj);
Assert.Equal("Baz", vdd.Eval("Foo.Bar"));
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:7,代码来源:ViewDataDictionaryTest.cs
示例17: createNewRandomPlayer
//Methods
public BasePlayer createNewRandomPlayer()
{
CreatePlayer player = new BasePlayer (string playerName, int playerID, int teamID, int macro,
int micro, int strategy, int multitasking, int scouting,
int score, int performance){
//Name
switchInt = Random.Range(1-10);
switch(switchInt)
{
case 1: playerName = "Janik von Rotz";
case 2: playerName = "Luca Kündig";
case 3: playerName = "Stefan Beeler";
case 4: playerName = "Reno Meyer";
case 5: playerName = "Alexander Hauck";
case 6: playerName = "Mike Monticoli";
case 7: playerName = "Kevin Stadelmann";
case 8: playerName = "Sandro Ritz";
case 9: playerName = "Michael Lötscher";
}
//ID
playerID = Random.Range (1-255
}
}
开发者ID:railgan,项目名称:Manager,代码行数:26,代码来源:CreatePlayer.cs
示例18: NewPath
Vector3[] NewPath()
{
Vector3 point1 = new Vector3 (-10,0);
Vector3 point2 = new Vector3(-5, Random.Range(-5, 5));
Vector3 point3 = new Vector3 (0, Random.Range(-5, 5));
Vector3[] datPath = new [] {point1, point2, point3};
return datPath;
}
开发者ID:TillusB,项目名称:GyroscopeGame,代码行数:8,代码来源:pathRandom.cs
示例19: About
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
var model = new { Title = "Test Liquid View Engine", Content = "Xin chào bạn đến với Hien's Blog" };
//return template.Render(Hash.FromAnonymousObject(new { Title = "Test Liquid view engine" }));
return View(model);
}
开发者ID:dodanghien23693,项目名称:Hien-sBlog,代码行数:8,代码来源:HomeController.cs
示例20: ShuffleTest_IntEnumerable
public void ShuffleTest_IntEnumerable()
{
IEnumerable original = new[] { 1, 2, 3, 4, 5 };
object obj = new ShuffleFormatter().Run(original, null, null, null);
Assert.IsNotNull(obj);
}
开发者ID:codesoda,项目名称:Impression,代码行数:8,代码来源:ShuffleTests.cs
注:本文中的System.Collections类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论