本文整理汇总了C#中ILookup类的典型用法代码示例。如果您正苦于以下问题:C# ILookup类的具体用法?C# ILookup怎么用?C# ILookup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILookup类属于命名空间,在下文中一共展示了ILookup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectAction
public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath.PathTemplate != "~/entityset/key/property")
{
return null;
}
var entitySetPathSegment = odataPath.Segments.OfType<EntitySetPathSegment>().Single();
var keyValuePathSegment = odataPath.Segments.OfType<KeyValuePathSegment>().Single();
var propertyAccessPathSegment = odataPath.Segments.OfType<PropertyAccessPathSegment>().Single();
var actionName = string.Format(CultureInfo.InvariantCulture, "GetPropertyFrom{0}", entitySetPathSegment.EntitySetName);
if (actionMap.Contains(actionName) && actionMap[actionName].Any(desc => MatchHttpMethod(desc, controllerContext.Request.Method)))
{
controllerContext.RouteData.Values.Add("propertyName", propertyAccessPathSegment.PropertyName);
if (!CompositeODataKeyHelper.TryEnrichRouteValues(keyValuePathSegment.Value, controllerContext.RouteData.Values))
{
controllerContext.RouteData.Values.Add("key", keyValuePathSegment.Value);
}
return actionName;
}
return null;
}
示例2: ShouldReplicateBlob
public static bool ShouldReplicateBlob(ILookup<string, string> headers, string container, string blob)
{
bool retval = false;
if (DashConfiguration.IsBlobReplicationEnabled)
{
bool evaluated = false;
string replicaMetadata = DashConfiguration.ReplicationMetadataName;
if (headers != null && !String.IsNullOrWhiteSpace(replicaMetadata))
{
string replicateHeader = "x-ms-meta-" + replicaMetadata;
if (headers.Contains(replicateHeader))
{
retval = String.Equals(DashConfiguration.ReplicationMetadataValue, headers[replicateHeader].First(), StringComparison.OrdinalIgnoreCase);
evaluated = true;
}
}
if (!evaluated)
{
if (_replicationPathExpression != null)
{
retval = _replicationPathExpression.IsMatch(PathUtils.CombineContainerAndBlob(container, blob));
}
}
}
return retval;
}
示例3: GetChildItem
private static ExplorerItem GetChildItem(ILookup<Type, ExplorerItem> elementTypeLookup, PropertyInfo childProp) {
// If the property's type is in our list of entities, then it's a Many:1 (or 1:1) reference.
// We'll assume it's a Many:1 (we can't reliably identify 1:1s purely from reflection).
if (elementTypeLookup.Contains(childProp.PropertyType))
return new ExplorerItem(childProp.Name, ExplorerItemKind.ReferenceLink, ExplorerIcon.ManyToOne) {
HyperlinkTarget = elementTypeLookup[childProp.PropertyType].First(),
// FormatTypeName is a helper method that returns a nicely formatted type name.
ToolTipText = DataContextDriver.FormatTypeName(childProp.PropertyType, true)
};
// Is the property's type a collection of entities?
Type ienumerableOfT = childProp.PropertyType.GetInterface("System.Collections.Generic.IEnumerable`1");
if (ienumerableOfT != null) {
Type elementType = ienumerableOfT.GetGenericArguments()[0];
if (elementTypeLookup.Contains(elementType))
return new ExplorerItem(childProp.Name, ExplorerItemKind.CollectionLink, ExplorerIcon.OneToMany) {
HyperlinkTarget = elementTypeLookup[elementType].First(),
ToolTipText = DataContextDriver.FormatTypeName(elementType, true)
};
}
// Ordinary property:
var isKey = childProp.GetCustomAttributes(false).Any(a => a.GetType().Name == "KeyAttribute");
return new ExplorerItem(childProp.Name + " (" + DataContextDriver.FormatTypeName(childProp.PropertyType, false) + ")",
ExplorerItemKind.Property, isKey ? ExplorerIcon.Key : ExplorerIcon.Column) { DragText = childProp.Name };
}
示例4: SelectAction
/// <summary>
/// Selects the action for OData requests.
/// </summary>
/// <param name="odataPath">The OData path.</param>
/// <param name="controllerContext">The controller context.</param>
/// <param name="actionMap">The action map.</param>
/// <returns>
/// <c>null</c> if the request isn't handled by this convention; otherwise, the name of the selected action
/// </returns>
public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath == null)
{
throw Error.ArgumentNull("odataPath");
}
if (controllerContext == null)
{
throw Error.ArgumentNull("controllerContext");
}
if (actionMap == null)
{
throw Error.ArgumentNull("actionMap");
}
if (odataPath.PathTemplate == "~")
{
return "GetServiceDocument";
}
if (odataPath.PathTemplate == "~/$metadata")
{
return "GetMetadata";
}
return null;
}
示例5: Select
private static ViewComponentDescriptor Select(
ILookup<string, ViewComponentDescriptor> candidates,
string name)
{
var matches = candidates[name];
var count = matches.Count();
if (count == 0)
{
return null;
}
else if (count == 1)
{
return matches.Single();
}
else
{
var matchedTypes = new List<string>();
foreach (var candidate in matches)
{
matchedTypes.Add(Resources.FormatViewComponent_AmbiguousTypeMatch_Item(
candidate.Type.FullName,
candidate.FullName));
}
var typeNames = string.Join(Environment.NewLine, matchedTypes);
throw new InvalidOperationException(
Resources.FormatViewComponent_AmbiguousTypeMatch(name, Environment.NewLine, typeNames));
}
}
示例6: AddDescendantNodes
protected virtual void AddDescendantNodes(
ISiteMap siteMap,
ISiteMapNode currentNode,
IList<ISiteMapNodeToParentRelation> sourceNodes,
ILookup<string, ISiteMapNodeToParentRelation> sourceNodesByParent,
HashSet<string> nodesAlreadyAdded)
{
if (sourceNodes.Count == 0)
{
return;
}
var children = sourceNodesByParent[currentNode.Key].OrderBy(x => x.Node.Order).ToArray();
if (children.Count() == 0)
{
return;
}
foreach (var child in children)
{
if (sourceNodes.Count == 0)
{
return;
}
this.AddAndTrackNode(siteMap, child, currentNode, sourceNodes, nodesAlreadyAdded);
if (sourceNodes.Count == 0)
{
return;
}
this.AddDescendantNodes(siteMap, child.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
}
}
示例7: AssertDescriptorMatches
void AssertDescriptorMatches(ILookup<string, SecurityAttributeDescriptor> descriptors, string signature, ICustomAttributeProvider element)
{
if (descriptors.Contains(signature))
AssertContainsAttribute(element, descriptors[signature].Single().AttributeTypeName);
else
AssertContainsNoAttribute(element);
}
示例8: SelectAction
public override string SelectAction(ODataPath odataPath, HttpControllerContext context,
ILookup<string, HttpActionDescriptor> actionMap)
{
if (context.Request.Method == HttpMethod.Get &&
odataPath.PathTemplate == "~/entityset/key/navigation/key")
{
NavigationPathSegment navigationSegment = odataPath.Segments[2] as NavigationPathSegment;
IEdmNavigationProperty navigationProperty = navigationSegment.NavigationProperty.Partner;
IEdmEntityType declaringType = navigationProperty.DeclaringType as IEdmEntityType;
string actionName = "Get" + declaringType.Name;
if (actionMap.Contains(actionName))
{
// Add keys to route data, so they will bind to action parameters.
KeyValuePathSegment keyValueSegment = odataPath.Segments[1] as KeyValuePathSegment;
context.RouteData.Values[ODataRouteConstants.Key] = keyValueSegment.Value;
KeyValuePathSegment relatedKeySegment = odataPath.Segments[3] as KeyValuePathSegment;
context.RouteData.Values[ODataRouteConstants.RelatedKey] = relatedKeySegment.Value;
return actionName;
}
}
// Not a match.
return null;
}
示例9: SelectAction
public string SelectAction(
ODataPath odataPath,
HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
return null;
}
示例10: SelectAction
/// <summary>
/// Selects the appropriate action based on the parsed OData URI.
/// </summary>
/// <param name="odataPath">Parsed OData URI</param>
/// <param name="controllerContext">Context for HttpController</param>
/// <param name="actionMap">Mapping from action names to HttpActions</param>
/// <returns>String corresponding to controller action name</returns>
public string SelectAction(
ODataPath odataPath,
HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
// TODO GitHubIssue#44 : implement action selection for $ref, navigation scenarios, etc.
Ensure.NotNull(odataPath, "odataPath");
Ensure.NotNull(controllerContext, "controllerContext");
Ensure.NotNull(actionMap, "actionMap");
if (!(controllerContext.Controller is RestierController))
{
// RESTier cannot select action on controller which is not RestierController.
return null;
}
HttpMethod method = controllerContext.Request.Method;
if (method == HttpMethod.Get && !IsMetadataPath(odataPath))
{
return MethodNameOfGet;
}
ODataPathSegment lastSegment = odataPath.Segments.LastOrDefault();
if (lastSegment != null && lastSegment.SegmentKind == ODataSegmentKinds.UnboundAction)
{
return MethodNameOfPostAction;
}
// Let WebAPI select default action
return null;
}
示例11: ContentTypeDetector
public ContentTypeDetector(IEnumerable<ContentType> contentTypes)
{
if (null == contentTypes)
throw new ArgumentNullException(nameof(contentTypes));
ContentTypes = contentTypes.ToArray();
ExtensionLookup = ContentTypes
.SelectMany(ct => ct.FileExts, (ct, ext) => new
{
ext,
ContentType = ct
})
.ToLookup(arg => arg.ext, x => x.ContentType, StringComparer.OrdinalIgnoreCase);
var mimeTypes = ContentTypes
.Select(ct => new
{
ct.MimeType,
ContentType = ct
});
var alternateMimeTypes = ContentTypes
.Where(ct => null != ct.AlternateMimeTypes)
.SelectMany(ct => ct.AlternateMimeTypes, (ct, mime) => new
{
MimeType = mime,
ContentType = ct
});
MimeLookup = alternateMimeTypes
.Union(mimeTypes)
.ToLookup(arg => arg.MimeType, x => x.ContentType, StringComparer.OrdinalIgnoreCase);
}
示例12: Hierarchy
/// <summary>
/// Where Tuple<int,int> represents a child_id|parent_id relationship
/// </summary>
/// <param name="relations"></param>
public Hierarchy(List<Relation> relations)
{
if (relations == null)
relations = new List<Relation>();
for (int i = 0; i < relations.Count; i++)
{
var item = relations[i];
if (item.Child == item.Parent)
continue;
// the child is a relation of itself; the parent is a relation of itself, too
this.Add(relations, new Relation { Child = item.Child, Parent = item.Child });
this.Add(relations, new Relation{ Child = item.Parent, Parent = item.Parent});
// if this 'parent' is the child of another item G, then this 'child' is also a child of G.
var grandparents = relations.Where(r => item.Parent == r.Child);
var grandchildren = relations.Where(r => r.Parent == item.Child).Select(r => r.Child);
var list = grandparents.Select(g => new Relation { Child = g.Child, Parent = item.Parent }).ToList();
foreach (var g in list)
this.Add(relations, g);
}
//parents = relations.GroupBy(i => i.Item1, i => i.Item2).ToLookup(g => g.Key, g => g.ToList());
parents = relations.ToLookup(i => i.Child, i => i.Parent);
children = relations.ToLookup(i => i.Parent, i => i.Child);
this.relationHash = new HashSet<int>(relations.Select(r => r.GetHashCode()));
}
示例13: InitCaches
public void InitCaches()
{
var db = new FacesDBDataContext(_connectionString);
_faceUKeyLookup = db.Faces.ToDictionary(x => x.FaceUKey, x => (api.Face) new FaceImpl(x, _m, null));
var query = (from f in db.Faces join p in db.Persons on f.PersonID equals p.PersonID select new { f, p });
_Faces = new Dictionary<api.Face,api.Person>();
Dictionary<int, api.Person> persons = new Dictionary<int,api.Person>();
foreach (var x in query) {
// todo; build pers dic at same time...
api.Person person = null;
if (!persons.TryGetValue(x.p.PersonID, out person))
{
person = (api.Person)new PersonImpl(x.p.FirstName, x.p.LastName, x.p.PersonID);
persons.Add(person.Id, person);
}
api.Face thisFace = _faceUKeyLookup[x.f.FaceUKey];
thisFace.Person = person;
_Faces.Add(thisFace, person);
}
_Persons = _Faces.GroupBy(x => x.Value).ToDictionary(x => x.Key, x => x.Select(y=>y.Key).ToList());
_allPersonsLookup = persons;
foreach (var pers in db.Persons) // add in other persons that don't have faces.
{
if (!_allPersonsLookup.ContainsKey(pers.PersonID))
_allPersonsLookup.Add(pers.PersonID, (api.Person)new PersonImpl(pers.FirstName, pers.LastName, pers.PersonID));
}
_PicturesToFaces = db.Faces
.ToLookup(x => x.PictureID, x => _faceUKeyLookup[x.FaceUKey]);
}
示例14: CommitDiffModel
public CommitDiffModel(string[] lines, IEnumerable<CommitCommentModel> comments, int fontSize)
{
Lines = lines;
FontSize = fontSize;
Comments = comments.ToList();
CommentsLookup = Comments.ToLookup(x => x.Line);
}
示例15: MenuService
public MenuService([NotNull] IServiceProvider serviceProvider)
{
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
var menuProviders = new ExtensionsCache<MenuProviderInfo, IMenuProvider>(serviceProvider);
_menuProvidersLookup =
menuProviders
.GetAllExtensions()
.ToLookup(
menuProvider => menuProvider.MenuName,
StringComparer.OrdinalIgnoreCase);
// WTF?
menuProviders
.GetAllExtensions()
.OfType<IDynamicMenuProvider>()
.Select(
dynamicMenuProvider =>
{
_menuCache.Drop(dynamicMenuProvider.MenuName);
return
dynamicMenuProvider.MenuChanged.Subscribe(
arg => _menuChanged.OnNext(dynamicMenuProvider.MenuName));
});
_menuCache = new ElementsCache<string, IMenuRoot>(CreateMenu);
}