本文整理汇总了C#中IReadOnlyDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyDictionary.TryGetValue方法的具体用法?C# IReadOnlyDictionary.TryGetValue怎么用?C# IReadOnlyDictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyDictionary
的用法示例。
在下文中一共展示了IReadOnlyDictionary.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PossiblyConvertBody
static object PossiblyConvertBody(object messageBody, IReadOnlyDictionary<string, string> headers)
{
var legacySubscriptionMessage = messageBody as LegacySubscriptionMessage;
if (legacySubscriptionMessage == null)
{
return messageBody;
}
string returnAddress;
var topic = legacySubscriptionMessage.Type;
if (!headers.TryGetValue(Headers.ReturnAddress, out returnAddress))
{
throw new RebusApplicationException($"Got legacy subscription message but the '{Headers.ReturnAddress}' header was not present on it!");
}
var subscribe = legacySubscriptionMessage.Action == 0;
if (subscribe)
{
return new SubscribeRequest
{
Topic = topic,
SubscriberAddress = returnAddress
};
}
return new UnsubscribeRequest
{
Topic = topic,
SubscriberAddress = returnAddress
};
}
示例2: LogManager
/// <summary>
/// Initializes the configured switches for <see cref="LogManager"/>.
/// </summary>
/// <param name="diagnosticsSection">The system.diagnostics configuration section.</param>
internal LogManager(ConfigurationSection diagnosticsSection)
{
SourceSwitch defaultSwitch;
configuredSources = GetConfiguredSources(diagnosticsSection);
configuredSwitches = GetConfiguredSwitches(diagnosticsSection);
defaultLevel = configuredSwitches.TryGetValue("default", out defaultSwitch) ? defaultSwitch.Level : SourceLevels.Warning;
}
示例3: GetBy
public string GetBy(IReadOnlyDictionary<string, string> context, string key)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (key == null) throw new ArgumentNullException(nameof(key));
string message;
context.TryGetValue(key, out message);
return message ?? @"N/A";
}
示例4: RewriteLocalVariables
private static void RewriteLocalVariables(MethodDefinition method, IReadOnlyDictionary<string, TypeDefinition> implMap)
{
foreach (var v in method.Body.Variables)
{
TypeDefinition target;
if (implMap.TryGetValue(v.VariableType.FullName, out target))
v.VariableType = target;
}
}
示例5: GetContentLength
private static int GetContentLength(IReadOnlyDictionary<string, string> headers)
{
var contentLength = 0;
string contentLengthString;
if (headers.TryGetValue("Content-Length", out contentLengthString))
{
contentLength = Convert.ToInt32(contentLengthString, CultureInfo.InvariantCulture);
}
return contentLength;
}
示例6: EmitSpecific
private static void EmitSpecific(short val, IReadOnlyDictionary<short, OpCode> map, OpCode generalCode, ILGenerator body)
{
OpCode code;
if (map.TryGetValue(val, out code))
{
body.Emit(code);
}
else
{
body.Emit(generalCode, val);
}
}
示例7: CreateProxy
public object CreateProxy(Type interfaceType, IReadOnlyDictionary<string, object> properties)
{
Guard.NotNull("interfaceType", interfaceType);
Guard.NotNull("properties", properties);
var typeDeclaration = new CodeTypeDeclaration(GetProxyClassName(interfaceType))
{
BaseTypes = { new CodeTypeReference(interfaceType) }
};
var proxyAssembly = new CodeCompileUnit
{
Namespaces =
{
new CodeNamespace(proxyNamespace)
{
Types = { typeDeclaration }
}
}
};
proxyAssembly.ReferencedAssemblies.Add(interfaceType.Assembly.Location);
proxyAssembly.ReferencedAssemblies.AddRange(
interfaceType.GetInterfaces().Select(i => i.Assembly.Location).ToArray());
foreach (var property in GetInterfaceProperties(interfaceType))
{
object value;
if (!properties.TryGetValue(property.Name, out value))
value = GetDefaultValue(property.PropertyType);
typeDeclaration.Members.Add(new CodeMemberProperty()
{
Attributes = MemberAttributes.Public | MemberAttributes.Final,
Name = property.Name,
HasGet = true,
GetStatements =
{
new CodeMethodReturnStatement(GetValueExpression(value))
},
Type = new CodeTypeReference(property.PropertyType)
});
}
using (var codeProvider = new CSharpCodeProvider())
{
return Activator.CreateInstance(
codeProvider
.CompileAssemblyFromDom(new CompilerParameters { GenerateInMemory = true }, proxyAssembly)
.CompiledAssembly
.GetType(proxyNamespace + "." + typeDeclaration.Name));
}
}
示例8: Escape
/// <summary>
/// Escapes the specified string.
/// </summary>
/// <param name="input">The string to escape.</param>
/// <param name="sequences">A dictionary with for each character to escape, the escape sequence.</param>
/// <returns>The escaped string.</returns>
public static string Escape(string input, IReadOnlyDictionary<char, string> sequences)
{
StringBuilder sb = new StringBuilder();
foreach (char ch in input)
{
string replacement;
if (sequences.TryGetValue(ch, out replacement))
sb.Append(replacement);
else
sb.Append(ch);
}
return sb.ToString();
}
示例9: CheckDeferHeaders
static void CheckDeferHeaders(IReadOnlyDictionary<string, string> headers)
{
// no problemo
if (!headers.ContainsKey(Headers.DeferredUntil)) return;
// recipient must have been set by now
string destinationAddress;
if (!headers.TryGetValue(Headers.DeferredRecipient, out destinationAddress)
|| destinationAddress == null)
{
throw new InvalidOperationException(
$"When you defer a message from a one-way client, you need to explicitly set the '{Headers.DeferredRecipient}' header in order to specify a recipient for the message when it is time to be delivered");
}
}
示例10: GetRanking
public static Ranking GetRanking(IReadOnlyDictionary<string, int> rankings, string id)
{
if (rankings == null)
{
throw new ArgumentNullException(nameof(rankings));
}
int rank = 0;
if (string.IsNullOrEmpty(id) || !rankings.TryGetValue(id, out rank))
{
return null;
}
return new Ranking { Id = string.Intern(id), Rank = rank };
}
示例11: ConstructUri
private void ConstructUri(IReadOnlyDictionary<String, Object> headers, String rawUri)
{
var requestUri = new Uri(rawUri, UriKind.RelativeOrAbsolute);
if (requestUri.IsAbsoluteUri)
{
RequestUri = requestUri;
}
else
{
Object host;
if (headers.TryGetValue("host", out host))
{
var baseUri = new Uri("http://" + (String)host);
requestUri = new Uri(baseUri, requestUri);
}
}
RequestUri = requestUri;
}
示例12: GetOrCreateProjectFromArgumentsAndReferences
private AbstractProject GetOrCreateProjectFromArgumentsAndReferences(
IWorkspaceProjectContextFactory workspaceProjectContextFactory,
string projectFilename,
IReadOnlyDictionary<string, DeferredProjectInformation> allProjectInfos,
IReadOnlyDictionary<string, string> targetPathsToProjectPaths)
{
var languageName = GetLanguageOfProject(projectFilename);
if (languageName == null)
{
return null;
}
DeferredProjectInformation projectInfo;
if (!allProjectInfos.TryGetValue(projectFilename, out projectInfo))
{
// This could happen if we were called recursively about a dangling P2P reference
// that isn't actually in the solution.
return null;
}
var commandLineParser = _workspaceServices.GetLanguageServices(languageName).GetService<ICommandLineParserService>();
var projectDirectory = PathUtilities.GetDirectoryName(projectFilename);
var commandLineArguments = commandLineParser.Parse(
projectInfo.CommandLineArguments,
projectDirectory,
isInteractive: false,
sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory());
// TODO: Should come from sln file?
var projectName = PathUtilities.GetFileName(projectFilename, includeExtension: false);
// `AbstractProject` only sets the filename if it actually exists. Since we want
// our ids to match, mimic that behavior here.
var projectId = File.Exists(projectFilename)
? GetOrCreateProjectIdForPath(projectFilename, projectName)
: GetOrCreateProjectIdForPath(projectName, projectName);
// See if we've already created this project and we're now in a recursive call to
// hook up a P2P ref.
AbstractProject project;
if (_projectMap.TryGetValue(projectId, out project))
{
return project;
}
OutputToOutputWindow($"\tCreating '{projectName}':\t{commandLineArguments.SourceFiles.Length} source files,\t{commandLineArguments.MetadataReferences.Length} references.");
var solution5 = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution5;
// If the index is stale, it might give us a path that doesn't exist anymore that the
// solution doesn't know about - be resilient to that case.
Guid projectGuid;
try
{
projectGuid = solution5.GetGuidOfProjectFile(projectFilename);
}
catch (ArgumentException)
{
var message = $"Failed to get the project guid for '{projectFilename}' from the solution, using random guid instead.";
Debug.Fail(message);
OutputToOutputWindow(message);
projectGuid = Guid.NewGuid();
}
// NOTE: If the indexing service fails for a project, it will give us an *empty*
// target path, which we aren't prepared to handle. Instead, convert it to a *null*
// value, which we do handle.
var outputPath = projectInfo.TargetPath;
if (outputPath == string.Empty)
{
outputPath = null;
}
var projectContext = workspaceProjectContextFactory.CreateProjectContext(
languageName,
projectName,
projectFilename,
projectGuid: projectGuid,
hierarchy: null,
binOutputPath: outputPath);
projectContext.SetOptions(projectInfo.CommandLineArguments.Join(" "));
foreach (var sourceFile in commandLineArguments.SourceFiles)
{
projectContext.AddSourceFile(sourceFile.Path);
}
foreach (var sourceFile in commandLineArguments.AdditionalFiles)
{
projectContext.AddAdditionalFile(sourceFile.Path);
}
var addedProjectReferences = new HashSet<string>();
foreach (var projectReferencePath in projectInfo.ReferencedProjectFilePaths)
{
// NOTE: ImmutableProjects might contain projects for other languages like
// Xaml, or Typescript where the project file ends up being identical.
var referencedProject = ImmutableProjects.SingleOrDefault(
p => (p.Language == LanguageNames.CSharp || p.Language == LanguageNames.VisualBasic)
&& StringComparer.OrdinalIgnoreCase.Equals(p.ProjectFilePath, projectReferencePath));
//.........这里部分代码省略.........
示例13: ParseSymbol
static bool ParseSymbol(VariableToken t, IReadOnlyDictionary<string, bool> symbols)
{
bool value;
symbols.TryGetValue(t.Symbol, out value);
return value;
}
示例14: CollectActivations
private static void CollectActivations(IReadOnlyDictionary<string, string> options, IEnumerable<string> args)
{
var silos = args.Select(ParseSilo).ToArray();
int ageLimitSeconds = 0;
string s;
if (options.TryGetValue("age", out s))
Int32.TryParse(s, out ageLimitSeconds);
var ageLimit = TimeSpan.FromSeconds(ageLimitSeconds);
if (ageLimit > TimeSpan.Zero)
systemManagement.ForceActivationCollection(silos, ageLimit);
else
systemManagement.ForceGarbageCollection(silos);
}
示例15: AddTransitions
private static void AddTransitions(IReadOnlyDictionary<Fact, IComponent> components)
{
foreach (KeyValuePair<Fact, IComponent> entry in components)
{
Fact sentence = entry.Key;
if (sentence.RelationName == GameContainer.Parser.TokNext)
{
//connect to true
Fact trueSentence = TrueProcessor.ProcessBaseFact(sentence);
IComponent nextComponent = entry.Value;
IComponent trueComponent;
//There might be no true component (for example, because the bases
//told us so). If that's the case, don't have a transition.
if (!components.TryGetValue(trueSentence, out trueComponent)) // Skipping transition to supposedly impossible 'trueSentence'
continue;
var transition = _componentFactory.CreateTransition();
transition.AddInput(nextComponent);
nextComponent.AddOutput(transition);
transition.AddOutput(trueComponent);
trueComponent.AddInput(transition);
}
}
}