本文整理汇总了C#中IDictionary.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.TryGet方法的具体用法?C# IDictionary.TryGet怎么用?C# IDictionary.TryGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.TryGet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ErrorViewModel
public ErrorViewModel(ErrorContext errorContext, IDictionary<string, object> routeValues, WikiDownConfig config)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
this.ClientMessage = (errorContext != null) ? errorContext.ClientData : null;
var exception = (errorContext != null) ? errorContext.Exception : null;
if (exception != null)
{
this.ExceptionContent = exception.ToString();
this.ExceptionMessage = exception.Message;
this.ExceptionTypeName = exception.GetType().Name;
}
if (routeValues != null)
{
this.ActionName = routeValues.TryGet("action") as string;
this.ControllerName = routeValues.TryGet("controller") as string;
}
this.config = config;
}
示例2: Event
public Event(String type, IDictionary<String, Object> eventInitDict = null)
: this()
{
var bubbles = eventInitDict.TryGet<Boolean>("bubbles") ?? false;
var cancelable = eventInitDict.TryGet<Boolean>("cancelable") ?? false;
Init(type, bubbles, cancelable);
}
示例3: For
public static MessageBody For(
string httpVersion, IDictionary<string, IEnumerable<string>> headers, Action continuation)
{
// see also http://tools.ietf.org/html/rfc2616#section-4.4
var keepAlive = httpVersion != "HTTP/1.0";
string connection;
if (headers.TryGet("Connection", out connection))
{
keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase);
}
string transferEncoding;
if (headers.TryGet("Transfer-Encoding", out transferEncoding))
{
return new ForChunkedEncoding(keepAlive, continuation);
}
string contentLength;
if (headers.TryGet("Content-Length", out contentLength))
{
return new ForContentLength(keepAlive, int.Parse(contentLength), continuation);
}
if (keepAlive)
{
return new ForContentLength(true, 0, continuation);
}
return new ForRemainingData(continuation);
}
示例4: KeyboardEvent
public KeyboardEvent(String type, IDictionary<String, Object> eventInitDict = null)
: base(type, eventInitDict)
{
Key = (eventInitDict.TryGet("key") ?? String.Empty).ToString();
Location = (KeyboardLocation)(eventInitDict.TryGet<Int32>("location") ?? 0);
IsRepeated = eventInitDict.TryGet<Boolean>("repeat") ?? false;
_modifiers = (eventInitDict.TryGet("code") ?? String.Empty).ToString();
}
示例5: WheelEvent
public WheelEvent(String type, IDictionary<String, Object> eventInitDict = null)
: base(type, eventInitDict)
{
DeltaX = eventInitDict.TryGet<Double>("deltaX") ?? 0.0;
DeltaY = eventInitDict.TryGet<Double>("deltaY") ?? 0.0;
DeltaZ = eventInitDict.TryGet<Double>("deltaZ") ?? 0.0;
DeltaMode = (WheelMode)(eventInitDict.TryGet<Int32>("deltaMode") ?? 0);
}
示例6: MouseEvent
public MouseEvent(String type, IDictionary<String, Object> eventInitDict = null)
: base(type, eventInitDict)
{
ScreenX = eventInitDict.TryGet<Int32>("screenX") ?? 0;
ScreenY = eventInitDict.TryGet<Int32>("screenY") ?? 0;
ClientX = eventInitDict.TryGet<Int32>("clientX") ?? 0;
ClientY = eventInitDict.TryGet<Int32>("clientY") ?? 0;
IsCtrlPressed = eventInitDict.TryGet<Boolean>("ctrlKey") ?? false;
IsMetaPressed = eventInitDict.TryGet<Boolean>("metaKey") ?? false;
IsShiftPressed = eventInitDict.TryGet<Boolean>("shiftKey") ?? false;
IsAltPressed = eventInitDict.TryGet<Boolean>("altKey") ?? false;
Button = (MouseButton)(eventInitDict.TryGet<Int32>("button") ?? 0);
Target = eventInitDict.TryGet("relatedTarget") as IEventTarget;
}
示例7: CecilCommandInputDescriptor
public CecilCommandInputDescriptor(PropertyDefinition property, IDictionary<string, object> inputAttrib)
{
IsValueRequired = property.PropertyType.FullName != typeof(bool).FullName;
_propertyName = property.Name;
inputAttrib.TryGet("Name", name => Name = (string)name);
inputAttrib.TryGet("Description", description => Description = (string)description);
inputAttrib.TryGet("IsValueRequired", _ => IsValueRequired = (bool)_);
inputAttrib.TryGet("IsRequired", _ => IsRequired = (bool)_);
inputAttrib.TryGet("Position", position => Position = (int)position);
Name = Name ?? property.Name;
Type = property.PropertyType.Name;
}
示例8: Settings
public Settings(IDictionary<string, string> settings)
{
this.Errors = new List<string>();
this.Path = settings.TryGet("path") ?? string.Empty;
if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(this.Path))
{
this.Errors.Add(string.Format("Directory {0} doesn't exists", this.Path));
}
this.ConnectionString = settings.TryGet("ConnectionString") ?? string.Empty;
this.UserVariables = settings
.Where(p => p.Key.StartsWith("$"))
.ToDictionary(p => p.Key.Substring(1), p => p.Value);
}
示例9: RedisLiveConnection
public RedisLiveConnection(IDictionary<string, string> settings)
{
if (!settings.TryGet("host", out _Host))
{
throw new Exception("Redis host is required");
}
_Port = settings.Get("port", 6379);
_Timeout = settings.Get("timeout", 2000);
}
示例10: CecilCommandDescriptor
public CecilCommandDescriptor(TypeDefinition typeDef, IDictionary<string, object> commandAttribute, IEnumerable<CecilCommandInputDescriptor> inputs)
{
Visible = true;
IsDefault = false;
commandAttribute.TryGet("Noun", noun => Noun = (string)noun);
commandAttribute.TryGet("Verb", verb => Verb = (string)verb);
commandAttribute.TryGet("Visible", visible => Visible = (bool)visible);
commandAttribute.TryGet("IsDefault", isDefault => IsDefault = (bool)isDefault);
var tokenPrefix = Verb + "-" + Noun;
commandAttribute.TryGet("Description", _ => Description = (string)_);
Description = Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix);
Inputs = inputs.ToDictionary(x => x.Name,
x =>
{
x.Description = x.Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix + "-" + x.Name);
return (ICommandInputDescriptor)x;
}, StringComparer.OrdinalIgnoreCase);
Factory = () => (ICommand)Activator.CreateInstanceFrom(typeDef.Module.FullyQualifiedName, typeDef.FullName).Unwrap();
}
示例11: DigitalChannel
public DigitalChannel(int slot, SignalSource signalSource, DataMapping data,
IDictionary<int, decimal> transpFreq, FavoritesIndexMode sortedFavorites, IDictionary<int, string> providerNames) :
base(data, sortedFavorites)
{
this.InitCommonData(slot, (SignalSource)((int)signalSource & ~(int)(SignalSource.TvAndRadio)), data);
if (!this.InUse || this.OldProgramNr == 0)
return;
this.InitDvbData(data, providerNames);
int transp = data.GetByte(_ChannelOrTransponder);
decimal freq = transpFreq.TryGet(transp);
if (freq == 0)
freq = LookupData.Instance.GetDvbtFrequeny(transp); // transp*8 + 106); // (106 = DVB-C; DVB-T=306?)
this.ChannelOrTransponder = transp.ToString();
this.FreqInMhz = freq;
}
示例12: GetOrCreateTypeByName
private ITypeDescription GetOrCreateTypeByName(TypeName name,
Func<TypeName, Maybe<IReflectClass>> classLookup,
IDictionary<string, ITypeDescription> knownTypes)
{
var type = knownTypes.TryGet(name.FullName);
if(type.HasValue)
{
return type.Value;
}
var systemType = typeResolver(name);
return systemType.Convert(KnownType.Create)
.GetValue(()=>classLookup(name)
.Convert(n=>CreateType(name, n, classLookup, knownTypes))
.GetValue(()=>MockTypeFor(name,knownTypes)));
}
示例13: CompositionEvent
public CompositionEvent(String type, IDictionary<String, Object> eventInitDict = null)
: base(type, eventInitDict)
{
Data = (eventInitDict.TryGet("data") ?? String.Empty).ToString();
}
示例14: InitDvbData
protected void InitDvbData(DataMapping data, IDictionary<int, string> providerNames)
{
this.ShortName = data.GetString(_ShortName, data.Settings.GetInt("lenShortName"));
this.ServiceId = data.GetWord(_ServiceId);
//this.PcrPid = data.GetWord(_PcrPid);
this.VideoPid = data.GetWord(_VideoPid);
this.AudioPid = data.GetWord(_AudioPid);
this.OriginalNetworkId = data.GetWord(_OriginalNetworkId);
this.TransportStreamId = data.GetWord(_TransportStreamId);
this.ServiceType = data.GetByte(_ServiceType);
this.SymbolRate = data.GetWord(_SymbolRate);
if (data.Settings.GetInt(_ServiceProviderId, -1) != -1)
{
int source = -1;
if ((this.SignalSource & SignalSource.MaskProvider) == SignalSource.Freesat)
source = 4;
else if ((this.SignalSource & SignalSource.MaskProvider) == SignalSource.TivuSat)
source = 6;
else if ((this.SignalSource & SignalSource.Antenna) != 0)
source = 0;
else if ((this.SignalSource & SignalSource.Cable) != 0)
source = 1;
else if ((this.SignalSource & SignalSource.Sat) != 0)
source = 3;
int providerId = data.GetWord(_ServiceProviderId);
this.Provider = providerNames.TryGet((source << 16) + providerId);
}
this.SignalSource |= LookupData.Instance.IsRadioOrTv(this.ServiceType);
}
示例15: CecilUICommandDescriptor
public CecilUICommandDescriptor(TypeDefinition typeDef, IDictionary<string, object> commandAttribute, IDictionary<string, object> uiAttribute, IEnumerable<CecilCommandInputDescriptor> inputs)
: base(typeDef, commandAttribute,inputs)
{
uiAttribute.TryGet("Label", label => Label = (string)label);
uiAttribute.TryGet("Context", context => Context = (UICommandContext)context);
}