本文整理汇总了C#中IDictionary.Single方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Single方法的具体用法?C# IDictionary.Single怎么用?C# IDictionary.Single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.Single方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Document
public Document(DocumentTable table, string document, IDictionary<string, object> projections)
{
Table = table;
DocumentAsString = document;
idColumn = projections.Single(x => x.Key == table.IdColumn.Name);
documentColumn = projections.Single(x => x.Key == table.DocumentColumn.Name);
etagColumn = projections.Single(x => x.Key == table.EtagColumn.Name);
this.projections = projections.Where(x => !(x.Key is SystemColumn))
.Select(x => new Projection(x.Key, x.Value))
.ToList();
}
示例2: Invoke
public async Task Invoke(IDictionary<string, object> environment)
{
//IOwinContext owinContext = new OwinContext(environment);
HttpContextBase httpContext = (HttpContextBase)environment.Single(context =>
context.Key == "System.Web.HttpContextBase").Value;
var url = httpContext.Request.Url;
if (url.AbsoluteUri.Contains("/Contact"))
{
httpContext.Response.Redirect("/");
}
else
{
await this._next.Invoke(environment);
}
}
示例3: CheckForExistingProperty
private static object CheckForExistingProperty(object item2, PropertyInfo fi, IDictionary<string, object> result)
{
var newValue = fi.GetValue(item2, null);
if (result.All(x => x.Key != fi.Name))
{
return newValue;
}
var foundProperty = result.Single(x => x.Key == fi.Name);
if (!foundProperty.Value.Equals(newValue))
{
throw new Exception("Merging Property with different values - " + fi.Name);
}
return newValue;
}
示例4: ExecuteAsync
public override Task<object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary<string, object> arguments, CancellationToken cancellationToken)
{
return TaskHelpers.RunSynchronously<object>(() =>
{
// create the changeset
object entity = arguments.Single().Value; // there is only a single parameter - the entity being submitted
ChangeSetEntry[] changeSetEntries = new ChangeSetEntry[]
{
new ChangeSetEntry
{
Id = 1,
ActionDescriptor = _updateAction,
Entity = entity,
Operation = _updateAction.ChangeOperation
}
};
ChangeSet changeSet = new ChangeSet(changeSetEntries);
changeSet.SetEntityAssociations();
DataController controller = (DataController)controllerContext.Controller;
if (!controller.Submit(changeSet) &&
controller.ActionContext.Response != null)
{
// If the submit failed due to an authorization failure,
// return the authorization response directly
return controller.ActionContext.Response;
}
// return the entity
entity = changeSet.ChangeSetEntries[0].Entity;
// REVIEW does JSON make sense here?
return new HttpResponseMessage()
{
Content = new ObjectContent(_updateAction.EntityType, entity, new JsonMediaTypeFormatter())
};
}, cancellationToken);
}
示例5: Load
private ISuiteProvider Load(
Type suiteType,
IDictionary<Type, ITypeLoader> loaderDictionary,
IDictionary<Type, Lazy<IAssemblySetup>> assemblySetups,
IIdentity assemblyIdentity)
{
// TODO: Move selection to AssemblyExplorer
var suiteTypeLoader = loaderDictionary.Single(x => x.Key == suiteType.GetAttribute<SuiteAttributeBase>().AssertNotNull().GetType()).Value;
return suiteTypeLoader.Load(suiteType, assemblySetups, assemblyIdentity);
}
示例6: RegisterInParents
private void RegisterInParents(DeviceInfo device, IDictionary<string, IPeripheral> parents)
{
foreach(var parentName in device.Connections.Keys)
{
//TODO: nongeneric version
var parent = parents.Single(x => x.Key == parentName).Value;
var connections = device.Connections[parentName];
var ifaces = parent.GetType().GetInterfaces().Where(x => IsSpecializationOfRawGeneric(typeof(IPeripheralRegister<,>), x)).ToList();
var ifaceCandidates = ifaces.Where(x => x.GetGenericArguments()[0].IsAssignableFrom(device.Peripheral.GetType())).ToList();
foreach(var connection in connections)
{
IRegistrationPoint regPoint = null;
Type formalType = null;
if(connection.ContainsKey(TYPE_NODE))
{
var name = (string)connection[TYPE_NODE];
formalType = GetDeviceTypeFromName(name);
}
Type foundIface = null;
foreach(var iface in ifaceCandidates)
{
var iRegPoint = iface.GetGenericArguments()[1];
Type objType;
if(formalType != null && iRegPoint.IsAssignableFrom(formalType))
{
objType = formalType;
}
else
{
objType = iRegPoint;
}
object regPointObject;
if(!TryInitializeCtor(objType, connection, out regPointObject))
{
if(connection.Keys.Any() || !TryHandleSingleton(objType, out regPointObject))
{
continue;
}
}
regPoint = (IRegistrationPoint)regPointObject;
foundIface = iface;
break;
//is a construable type
}
if(foundIface == null)
{
// let's try attachment through the AttachTo mechanism
FailDevice(device.Name, "connection to " + parentName);
}
else
{
Dynamic.InvokeMemberAction(parent, "Register", new object[] {
device.Peripheral,
regPoint
}
);
}
}
}
}
示例7: BuildResponse
/// <summary>
/// Builds the response.
/// </summary>
/// <param name="content">The content.</param>
/// <returns></returns>
protected IDictionary<string, object> BuildResponse(object serializableObject, IDictionary<string, object> serializedContent)
{
// create body of the response
IDictionary<string, object> response = new Dictionary<string, object>();
response.Add("timestamp", DateTime.UtcNow);
// add serialization headers to the response
foreach (var header in SerializedHeader)
response.Add(header.Key, header.Value);
// check for regular collection
if (serializableObject is ICollection)
response.Add("count", ((ICollection)serializableObject).Count);
// check if only one object was returned, if it was then we can rename the root
if (serializedContent.Count == 1)
{
var rootObj = serializedContent.Single();
var rootName = rootObj.Key;
if (!String.IsNullOrWhiteSpace(SerializedRootName))
rootName = SerializedRootName;
response.Add(rootName, rootObj.Value);
}
else
foreach (var item in serializedContent)
response.Add(item);
return response;
}