本文整理汇总了C#中IAnalysisSet.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IAnalysisSet.OfType方法的具体用法?C# IAnalysisSet.OfType怎么用?C# IAnalysisSet.OfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAnalysisSet
的用法示例。
在下文中一共展示了IAnalysisSet.OfType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIndex
public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) {
var res = base.GetIndex(node, unit, index);
var names = index.OfType<ConstantInfo>()
.Select(ci => ci.GetConstantValueAsString())
.Where(s => !string.IsNullOrEmpty(s))
.Distinct()
.ToArray();
if (names.Length != 1) {
// Unless you request a specific module by string literal,
// you won't get any object out of sys.modules.
return AnalysisSet.Empty;
}
var name = names[0];
lock (_owner.Modules) {
IAnalysisSet knownValues;
if (_owner.Modules.TryGetValue(name, out knownValues) &&
knownValues != null &&
knownValues.Any()
) {
return knownValues;
}
}
ModuleReference modRef;
if (unit.ProjectState.Modules.TryImport(name, out modRef)) {
return modRef.AnalysisModule;
}
return AnalysisSet.Empty;
}
示例2: SetIndex
public override void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) {
base.SetIndex(node, unit, index, value);
foreach (var name in index.OfType<ConstantInfo>()
.Select(ci => ci.GetConstantValueAsString())
.Where(s => !string.IsNullOrEmpty(s))
) {
lock (_owner.Modules) {
_owner.Modules[name] = value;
}
var modules = value.OfType<ModuleInfo>().ToArray();
var modRef = unit.ProjectState.Modules.GetOrAdd(name);
MultipleMemberInfo mmi;
ModuleInfo mi;
if ((mmi = modRef.Module as MultipleMemberInfo) != null) {
if (modules.Except(mmi.Members.OfType<ModuleInfo>()).Any()) {
modules = modules.Concat(mmi.Members.OfType<ModuleInfo>()).Distinct().ToArray();
}
} else if ((mi = modRef.Module as ModuleInfo) != null) {
if (!modules.Contains(mi)) {
modules = modules.Concat(Enumerable.Repeat(mi, 1)).ToArray();
}
}
modRef.Module = MultipleMemberInfo.Create(modules) as IModule;
foreach (var module in modules) {
int lastDot = name.LastIndexOf('.');
if (lastDot > 0) {
var parentName = name.Remove(lastDot);
ModuleReference parent;
if (ProjectState.Modules.TryImport(parentName, out parent)) {
if ((mi = parent.AnalysisModule as ModuleInfo) != null) {
mi.AddChildPackage(module, unit, name.Substring(lastDot + 1));
}
}
}
}
}
}