本文整理汇总了C#中KeyValuePair.Select方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValuePair.Select方法的具体用法?C# KeyValuePair.Select怎么用?C# KeyValuePair.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileJumpTarget
private static void CompileJumpTarget(KeyValuePair<int, ProxyRule>[] rules, ProxyRule rule)
{
if (rule.Action == MatchAction.GotoName) {
rule.Action = MatchAction.Goto;
rule._jumpTarget = ((rules.Select((e, i) => new { Index = i, Item = e }).FirstOrDefault(x => x.Item.Value.Name == rule.ActionString)?.Index) ?? rules.Length - 1);
} else if (rule.Action == MatchAction.Goto) {
int number;
if (!int.TryParse(rule.ActionString, out number)) number = int.MaxValue;
rule._jumpTarget = rules.Select((e, i) => new { Index = i, Item = e }).First(x => x.Item.Key >= number).Index;
}
}
示例2: PackageSolution
public IServiceResult PackageSolution(string solutionPath, string buildConfiguration, KeyValuePair<string, string>[] buildProperties)
{
if (string.IsNullOrWhiteSpace(solutionPath))
{
return new FailureResult(Resources.SolutionPackagingService.ErrorSolutionPathParameterCannotBeEmpty);
}
if (string.IsNullOrWhiteSpace(buildConfiguration))
{
return new FailureResult(Resources.SolutionPackagingService.ErrorBuildConfigurationParameterCannotBeEmpty);
}
if (buildProperties == null)
{
return new FailureResult(Resources.SolutionPackagingService.ErrorBuildPropertiesParameterCannotBeNull);
}
// Build the solution
IServiceResult buildResult = this.solutionBuilder.Build(solutionPath, buildConfiguration, buildProperties);
if (buildResult.Status == ServiceResultType.Failure)
{
return
new FailureResult(
Resources.SolutionPackagingService.BuildFailedMessageTemplate,
solutionPath,
buildConfiguration,
string.Join(",", buildProperties.Select(p => p.Key + "=" + p.Value)))
{
InnerResult = buildResult
};
}
// pre-packaging
IServiceResult prepackagingResult = this.prepackagingService.Prepackage(this.buildFolder);
if (prepackagingResult.Status == ServiceResultType.Failure)
{
return new FailureResult(Resources.SolutionPackagingService.PrepackagingFailedMessageTemplate, solutionPath) { InnerResult = prepackagingResult };
}
// packaging
IServiceResult packageResult = this.packagingService.Package();
if (packageResult.Status == ServiceResultType.Failure)
{
return new FailureResult(Resources.SolutionPackagingService.PackagingFailedMessageTemplate, solutionPath) { InnerResult = packageResult };
}
string packagePath = packageResult.ResultArtefact;
return
new SuccessResult(
Resources.SolutionPackagingService.PackagingSucceededMessageTemplate,
solutionPath,
buildConfiguration,
string.Join(",", buildProperties.Select(p => p.Key + "=" + p.Value)),
packagePath)
{
ResultArtefact = packagePath
};
}
示例3: KeyCollection
public void KeyCollection(JaggedDictionary<int, string> sut, KeyValuePair<JaggedIndex4<int>, string>[] values)
{
foreach (var kvp in values) sut[kvp.Key] = kvp.Value;
var debugView = new JaggedDictionaryKeyCollectionDebugView<int, string>(sut.Keys);
var items = debugView.Items;
Assert.Equal(values.Select(kvp => kvp.Key).Distinct().Count(), items.Length);
}
示例4: NormalizedGraphSearchTest
public NormalizedGraphSearchTest()
{
store = new Store(@"..\..\..\Databases\int based\");
store.ClearAll();
//Performance.ComputeTime(() => store.ReloadFrom(Config.Source_data_folder_path + "10M.ttl"), "load 10 млн ", true);
store.ReloadFrom(@"C:\deployed\triples.ttl");
store.NodeGenerator.TryGetUri(new OV_iri("http://fogid.net/o/collection-item"), out collectionItempredicate);
var triplesCount = store.GetTriplesCount();
store.NodeGenerator.TryGetUri(new OV_iri("http://fogid.net/o/in-collection"), out inCollectionPredicate);
edges = (from triple in store.GetTriplesWithPredicate(collectionItempredicate)
from item in store.GetTriplesWithSubjectPredicate(triple.Subject, inCollectionPredicate)
select new KeyValuePair<int, int>((int)item.WritableValue, (int)triple.Object.WritableValue)).ToArray();
vertexes = edges.Select(pair => pair.Key).Concat(edges.Select(pair => pair.Value)).Distinct();
normalizedGraph4Search = new NormalizedGraph4Search(@"..\..\..\Databases\int based\tree\");
normalizedGraph4Search.ReCreate(edges);
var allSubTree = normalizedGraph4Search.GetAllSubTree(edges[0].Key);
}
示例5: RunCmdlet
public static void RunCmdlet(this PSCmdlet cmdlet, string parameterSet, KeyValuePair<string, object[]>[] incomingValues)
{
var cmdletType = cmdlet.GetType();
parameterSetFieldInfo.SetValue(cmdlet, parameterSet);
beginProcessingMethodInfo.Invoke(cmdlet, emptyParameters);
var parameterProperties = incomingValues.Select(x =>
new Tuple<PropertyInfo, object[]>(
cmdletType.GetProperty(x.Key),
x.Value)).ToArray();
for (int i = 0; i < incomingValues[0].Value.Length; i++)
{
foreach (var parameter in parameterProperties)
{
parameter.Item1.SetValue(cmdlet, parameter.Item2[i], null);
}
processRecordMethodInfo.Invoke(cmdlet, emptyParameters);
}
endProcessingMethodInfo.Invoke(cmdlet, emptyParameters);
}
示例6: GetDeviceImageRotater
/// <summary>
/// Gets an image control with mouse events required to rotate the image cycle on mouse over. Returns null if
/// no image is available.
/// </summary>
/// <param name="deviceURL"></param>
/// <param name="images"></param>
/// <returns></returns>
internal static System.Web.UI.WebControls.WebControl GetDeviceImageRotater(KeyValuePair<string, Uri>[] images, string deviceURL)
{
HyperLink deviceLink = new HyperLink();
deviceLink.NavigateUrl = deviceURL;
if (images != null)
{
System.Web.UI.WebControls.Image deviceImage = new System.Web.UI.WebControls.Image();
if (images.Length > 0)
{
deviceImage.ImageUrl = images[0].Value.ToString();
// Hover events are only useful if there are extra images to cycle to
if (images.Length > 1)
{
string[] imageUrls = images.Select(i => String.Format("'{0}'", i.Value)).ToArray();
// Create onmouseover event. It creates an array of url strings that should be cycled in order
string mouseOver = String.Format("ImageHovered(this, new Array({0}))",
String.Join(",", imageUrls)
);
// Create onmouseout event. It is passed a single url string that should be loaded when the cursor leaves the image
string mouseOff = String.Format("ImageUnHovered(this, '{0}')", images[0].Value.ToString());
deviceImage.Attributes.Add("onmouseover", mouseOver.Replace("\\", "\\\\"));
deviceImage.Attributes.Add("onmouseout", mouseOff.Replace("\\", "\\\\"));
}
}
else // there are no images availble, so use the unknown one
deviceImage.ImageUrl = UNKNOWN_IMAGE_URL;
deviceImage.Height = Unit.Pixel(128);
deviceImage.Width = Unit.Pixel(128);
deviceLink.Controls.Add(deviceImage);
return deviceLink;
}
else
return null;
}
示例7: ShouldPutMultiple
public void ShouldPutMultiple()
{
_db = _txn.OpenDatabase(configuration: new DatabaseConfiguration { Flags = DatabaseOpenFlags.DuplicatesFixed | DatabaseOpenFlags.Create });
var values = new[] { 1, 2, 3, 4, 5 }.Select(BitConverter.GetBytes).ToArray();
using (var cur = _txn.CreateCursor(_db))
cur.PutMultiple(UTF8.GetBytes("TestKey"), values);
var pairs = new KeyValuePair<byte[], byte[]>[values.Length];
using (var cur = _txn.CreateCursor(_db))
{
for (var i = 0; i < values.Length; i++)
{
cur.MoveNextDuplicate();
pairs[i] = cur.Current;
}
}
Assert.Equal(values, pairs.Select(x => x.Value).ToArray());
}
示例8: Scatter
public Scatter(KeyValuePair<double, double>[] Points)
{
points = Points.Select(i => new PointF((float)i.Key, ToFloat(i.Value))).ToArray();
}
示例9: CopyTo_should_copy_values
public void CopyTo_should_copy_values()
{
var dict = CreateTwoItemDictionary();
var copy = new KeyValuePair<int, string>[2];
dict.CopyTo(copy, 0);
Assert.That(copy.Select(v => v.Value).ToArray(),
Is.EquivalentTo(new[] { "35A", "35B"}));
}
示例10: AddFunction
private void AddFunction(PrimitiveTypeKind returnType, string functionName, KeyValuePair<string, PrimitiveTypeKind>[] parameterDefinitions)
{
FunctionParameter returnParameter = CreateReturnParameter(returnType);
FunctionParameter[] parameters = parameterDefinitions.Select(paramDef => CreateParameter(paramDef.Value, paramDef.Key)).ToArray();
EdmFunction function = new EdmFunction(functionName,
EdmConstants.EdmNamespace,
DataSpace.CSpace,
new EdmFunctionPayload
{
IsBuiltIn = true,
ReturnParameters = new FunctionParameter[] {returnParameter},
Parameters = parameters,
IsFromProviderManifest = true,
});
function.SetReadOnly();
this.functions.Add(function);
}
示例11: GetSetTest
public static void GetSetTest(ListDictionary ld, KeyValuePair<string, string>[] data)
{
DictionaryEntry[] translated = data.Select(kv => new DictionaryEntry(kv.Key, kv.Value)).ToArray();
foreach (KeyValuePair<string, string> kv in data)
{
Assert.Equal(kv.Value, ld[kv.Key]);
}
for (int i = 0; i < data.Length / 2; i++)
{
object temp = ld[data[i].Key];
ld[data[i].Key] = ld[data[data.Length - i - 1].Key];
ld[data[data.Length - i - 1].Key] = temp;
}
for (int i = 0; i < data.Length; i++)
{
Assert.Equal(data[data.Length - i - 1].Value, ld[data[i].Key]);
}
}
示例12: StreamPropertyNoMetadataAtomTest
//.........这里部分代码省略.........
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity()
.XmlRepresentation(@"<entry>
<link rel='http://docs.oasis-open.org/odata/ns/mediaresource' href='http://odata.org/readlink' />
</entry>"),
},
// verify that incomplete rel is not recognized as stream property (missing the last slash in edit link)
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity()
.XmlRepresentation(@"<entry>
<link rel='http://docs.oasis-open.org/odata/ns/edit-media' href='http://odata.org/editlink' />
</entry>"),
},
#endregion
#region order of the attributes and link
// edit link first.
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity()
.StreamProperty("StreamProperty1", null, "http://odata.org/editlink", null, null)
.StreamProperty("StreamProperty2", "http://odata.org/readlink", null, null, null),
},
// read link first.
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity()
.StreamProperty("StreamProperty1", "http://odata.org/readlink", null, null, null)
.StreamProperty("StreamProperty2", null, "http://odata.org/editlink", null, null),
},
// rel after etag, href and type.
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity().StreamProperty("StreamProperty", null, "http://odata.org/editlink", "application/atom+xml", "some_etag")
.XmlRepresentation(@"<entry>
<link m:etag='some_etag' href='http://odata.org/editlink' type='application/atom+xml' rel='http://docs.oasis-open.org/odata/ns/edit-media/StreamProperty'/>
</entry>"),
},
#endregion order of the attributes and link
#region content inside link element
// verify that all contents inside link element are skipped.
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity()
.StreamProperty("StreamProperty", null, "http://odata.org/editlink", "application/atom+xml", null)
.XmlRepresentation(@"<entry>
<link href='http://odata.org/editlink' type='application/atom+xml' rel='http://docs.oasis-open.org/odata/ns/edit-media/StreamProperty'>
<m:unknown>some text</m:unknown>
<!-- Some comments -->
<d:unknown/>
<ns:someelement xmlns:ns='somenamespace'/>
<![CDATA[cdata]]>
</link>
</entry>"),
},
#endregion content inside link element
};
#region empty or missing etag
KeyValuePair<string, string>[] etags = new KeyValuePair<string, string>[]
{
new KeyValuePair<string, string>(string.Empty, "m:etag=''"), // empty etag
new KeyValuePair<string, string>("some_etag", "m:etag='some_etag'"), // valid etag
new KeyValuePair<string, string>(null, "foo:etag='some_etag'"), // etag in a different namespace
};
testDescriptors = testDescriptors.Concat(etags.Select(etag =>
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = PayloadBuilder.Entity().StreamProperty("StreamProperty", null, "http://odata.org/editlink", null, etag.Key)
.XmlRepresentation(string.Format(@"<entry xmlns:foo='http://www.w3.org/SomeNamespace'>
<link rel='http://docs.oasis-open.org/odata/ns/edit-media/StreamProperty'
href='http://odata.org/editlink' {0} />
</entry>", etag.Value)),
}));
#endregion empty or missing etag
// WCF DS client, server and default ODataLib show the same behavior for stream properties.
this.CombinatorialEngineProvider.RunCombinations(
TestReaderUtils.ODataBehaviorKinds,
testDescriptors,
this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
(behaviorKind, testDescriptor, testConfiguration) =>
{
if (testConfiguration.IsRequest)
{
testDescriptor = new PayloadReaderTestDescriptor(testDescriptor)
{
ExpectedException = null,
ExpectedResultPayloadElement = tc => RemoveStreamPropertyPayloadElementNormalizer.Normalize(testDescriptor.PayloadElement.DeepCopy())
};
}
testDescriptor.RunTest(testConfiguration.CloneAndApplyBehavior(behaviorKind));
});
}
示例13: Message_Tranfer_Arbol_Union
public static void Message_Tranfer_Arbol_Union(MarkovNet arboldeunion, KeyValuePair<BayesianNode, int>[] evidence = null)
{
//absorber evidence
if (evidence != null && evidence.Length > 0)
{
arboldeunion.BayesianNet.Evidence = evidence.Select(x => x.Value).ToArray();
}
if (arboldeunion.Count() > ParalellStartNumber)
{
#region ParalellAlgorithm
arboldeunion.Debug = true;
var taskarr = new Task[arboldeunion.Count];
for (int i = 0; i < arboldeunion.Count; i++)
{
taskarr[i] = new Task(o =>
{
var node = o as BayesianNode;
if (node != null)
lock (node)
{
do
{
arboldeunion.Work(node);
} while (!node.Finished);
}
}, arboldeunion[i]);
taskarr[i].Start();
}
for (int i = 0; i < arboldeunion.Count*8; i++)
{
System.Threading.Thread.Sleep(300);
Increment();
}
Task.WaitAll(taskarr);
arboldeunion.Debug = false;
#endregion
}
else
#region DeterministicAlgorithm
while (!arboldeunion.AllConditionalProbabilitiesComputed())
{
foreach (var item in arboldeunion)
{
arboldeunion.Work(item);
}
Increment();
}
#endregion
foreach (var node in arboldeunion.BayesianNet)
arboldeunion.Marginalize_X(node);
}
示例14: RedisStorageStoresAndRemovesObjectsInBulks
public void RedisStorageStoresAndRemovesObjectsInBulks()
{
KeyValuePair<string, string>[] objectsToStore = new KeyValuePair<string, string>[100];
for (int i = 0; i < objectsToStore.Length; i++)
{
objectsToStore[i] = new KeyValuePair<string, string>(Guid.NewGuid().ToString(), "jack checked chicken");
}
using (var storage = new RedisStorage(RedisStorageTests.Host))
{
storage.BulkStore(objectsToStore);
storage.BulkRemove(objectsToStore.Select(o => o.Key).ToArray());
foreach (var @object in objectsToStore)
{
Assert.That(() => storage.Retrieve<string>(@object.Key),
Throws.InstanceOf<ArgumentOutOfRangeException>());
}
}
}
示例15: RedisStorageStoresAndRetrievesComplexObjectsInBulks
public void RedisStorageStoresAndRetrievesComplexObjectsInBulks()
{
var objectToStore = new ComplexParameter()
{
SomeProperty = "this is string",
AnotherProperty = 47
};
KeyValuePair<string, ComplexParameter>[] objectsToStore = new KeyValuePair<string, ComplexParameter>[100];
for (int i = 0; i < objectsToStore.Length; i++)
{
objectsToStore[i] = new KeyValuePair<string, ComplexParameter>(Guid.NewGuid().ToString(), objectToStore);
}
using (var storage = new RedisStorage(RedisStorageTests.Host))
{
storage.BulkStore(objectsToStore);
var retrievedObjects = storage.BulkRetrieve<ComplexParameter>(objectsToStore.Select(o => o.Key).ToArray());
foreach (var retrievedObject in retrievedObjects)
{
retrievedObject.SomeProperty.ShouldBe(objectToStore.SomeProperty);
retrievedObject.AnotherProperty.ShouldBe(objectToStore.AnotherProperty);
}
}
}