本文整理汇总了C#中System.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# System.Cast方法的具体用法?C# System.Cast怎么用?C# System.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertSeparators
private IEnumerable<object> InsertSeparators( System.Collections.IEnumerable a, string sSeparator )
{
if ( a.Cast<object> ( ).Any ( ) )
{
yield return a.Cast<object> ( ).First ( );
foreach ( var o in a.Cast<object> ( ).Skip ( 1 ) )
{
yield return sSeparator;
yield return o;
}
}
}
示例2: ShowUsingMapView
public void ShowUsingMapView()
{
var points = new[,]
{
{new Point(0, 0), new Point(1, 0), new Point(2, 0)},
{new Point(0, 1), new Point(1, 1), new Point(2, 1)},
};
var coverage = new DiscreteGridPointCoverage(2, 3, points.Cast<IPoint>());
var values = new[,]
{
{1.0, 2.0},
{3.0, 4.0},
{5.0, 6.0}
};
coverage.SetValues(values);
var coverageLayer = new DiscreteGridPointCoverageLayer {Coverage = coverage};
var map = new Map {Layers = {coverageLayer}};
MapTestHelper.ShowModal(map);
}
示例3: Inbox_support_queueing_multiple_queries
public void Inbox_support_queueing_multiple_queries()
{
var tasks = new[]
{
Task.Factory.StartNew(() => _inbox.Receive()),
Task.Factory.StartNew(() =>
{
Thread.Sleep(100);
return _inbox.ReceiveWhere(x => x.ToString() == "world");
}),
Task.Factory.StartNew(() =>
{
Thread.Sleep(200);
return _inbox.ReceiveWhere(x => x.ToString() == "hello");
})
};
_inbox.Receiver.Tell(42);
_inbox.Receiver.Tell("hello");
_inbox.Receiver.Tell("world");
Task.WaitAll(tasks.Cast<Task>().ToArray());
tasks[0].Result.ShouldBe(42);
tasks[1].Result.ShouldBe("world");
tasks[2].Result.ShouldBe("hello");
}
示例4: CommandComputer
public CommandComputer(System.Collections.IList iList)
{
// TODO: Complete member initialization
this.clients = (List<ClientThread>)iList.Cast<ClientThread>().ToList() ;
InitializeComponent();
}
示例5: FillControls
public static void FillControls(Dictionary<string, string> collection, System.Windows.Forms.Control.ControlCollection controls)
{
foreach (Control control in controls.Cast<Control>().Where(y => y.Tag != null).OrderBy(y => y.TabIndex))
{
FillControl(collection, control);
}
}
示例6: ShowUsingMapViewWhereValuesContainNoDataValue
public void ShowUsingMapViewWhereValuesContainNoDataValue()
{
var points = new[,]
{
{new Point(0, 0), new Point(1, 0)},
{new Point(2, 1), new Point(3, 1.5)},
{new Point(1, 2), new Point(3, 3)}
};
var coverage = new DiscreteGridPointCoverage(2, 3, points.Cast<IPoint>());
var values = new[,]
{
{1.0, 2.0},
{3.0, 4.0},
{5.0, -999.0}
};
coverage.Components[0].NoDataValues = new [] {-999.0};
coverage.SetValues(values);
var coverageLayer = new DiscreteGridPointCoverageLayer { Coverage = coverage };
var map = new Map { Layers = { coverageLayer } };
MapTestHelper.ShowModal(map);
}
示例7: CallsMemberGenerators
public void CallsMemberGenerators()
{
var spies = new[]{new SpyGenerator(), new SpyGenerator()};
var memberGenerators = spies.Cast<CodeGeneratorBase>().ToArray();
Generator = new NamespaceGenerator(Configuration, memberGenerators);
Generator.Generate(compileUnit, ContentType);
Assert.That(spies.All(s => s.Called));
}
示例8: WhenAnyWeightsArrayElementDoesNotPointToArray_Throw
public void WhenAnyWeightsArrayElementDoesNotPointToArray_Throw()
{
var array1 = new[] { 1.1, 1.2 };
ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray());
Action action = () => ExcelFunctions.MakeWeights("weights", new object[] {"array1", "array2"});
action.ShouldThrow<NNXException>()
.WithMessage("*Element at index 2 ('array2') does not point to a valid array of numbers.*");
}
示例9: Write
public bool Write(System.Collections.Generic.IEnumerable<char> buffer)
{
return this.backend.Write(buffer.Cast(c =>
{
this.OnWrite.Call(c);
return c;
}));
}
示例10: SelectAllItems
public void SelectAllItems(System.ComponentModel.ICollectionView availableItemsCollectionView)
{
IList<Property> itemsList = new List<Property>(availableItemsCollectionView.Cast<Property>());
foreach (Property obj in itemsList)
{
SelectItem(obj);
}
}
示例11: WhenAnyWeightsArrayElementIsNotDoubleArray_Throw
public void WhenAnyWeightsArrayElementIsNotDoubleArray_Throw(object bad)
{
var array1 = new[] { 1.1, 1.2 };
ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray());
ObjectStore.Add("bad", bad);
Action action = () => ExcelFunctions.MakeWeights("weights", new object[] { "array1", "bad" });
action.ShouldThrow<NNXException>()
.WithMessage("*Element at index 2 ('bad') does not point to a valid array of numbers.*");
}
示例12: ShouldReturnObjectName
public void ShouldReturnObjectName()
{
var array1 = new[] { 1.1, 1.2 };
var array2 = new[] { 2.1, 2.2, 2.3 };
ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray());
ExcelFunctions.MakeArray("array2", array2.Cast<object>().ToArray());
var name = ExcelFunctions.MakeWeights("weights", new object[] { "array1", "array2" });
name.Should().Be("weights");
}
示例13: GetCacheDependency
public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{
if (virtualPathDependencies == null)
{
return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
return Previous.GetCacheDependency(virtualPath, virtualPathDependencies.Cast<string>().Where(vp => GetCompiledType(vp) == null), utcStart);
}
示例14: SpecificationsMatchesConstructorSpecifications
public void SpecificationsMatchesConstructorSpecifications()
{
// Fixture setup
var expectedSpecifications = new[] { new DelegatingRequestSpecification(), new DelegatingRequestSpecification(), new DelegatingRequestSpecification() };
var sut = new AndRequestSpecification(expectedSpecifications.Cast<IRequestSpecification>());
// Exercise system
IEnumerable<IRequestSpecification> result = sut.Specifications;
// Verify outcome
Assert.True(expectedSpecifications.SequenceEqual(result));
// Teardown
}
示例15: WhenGivenArrayList_ShouldMakeWeights
public void WhenGivenArrayList_ShouldMakeWeights()
{
var array1 = new[] {1.1, 1.2};
var array2 = new[] {2.1, 2.2, 2.3};
ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray());
ExcelFunctions.MakeArray("array2", array2.Cast<object>().ToArray());
ExcelFunctions.MakeWeights("weights", new object[] {"array1", "array2"});
var result = ObjectStore.Get<double[][]>("weights");
result.Should().HaveCount(2);
result[0].Should().Equal(array1);
result[1].Should().Equal(array2);
}