本文整理汇总了C#中Compilation.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.GetMembers方法的具体用法?C# Compilation.GetMembers怎么用?C# Compilation.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compilation
的用法示例。
在下文中一共展示了Compilation.GetMembers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethodOrTypeBySignature
internal static Symbol GetMethodOrTypeBySignature(Compilation compilation, string signature)
{
string[] parameterTypeNames;
var methodOrTypeName = ExpressionCompilerTestHelpers.GetMethodOrTypeSignatureParts(signature, out parameterTypeNames);
var candidates = compilation.GetMembers(methodOrTypeName);
var methodOrType = (parameterTypeNames == null) ?
candidates.FirstOrDefault() :
candidates.FirstOrDefault(c => parameterTypeNames.SequenceEqual(((MethodSymbol)c).Parameters.Select(p => p.Type.Name)));
Assert.False(methodOrType == null, "Could not find method or type with signature '" + signature + "'.");
return methodOrType;
}
示例2: GetMethodOrTypeBySignature
internal static Symbol GetMethodOrTypeBySignature(Compilation compilation, string signature)
{
string methodOrTypeName = signature;
string[] parameterTypeNames = null;
var parameterListStart = methodOrTypeName.IndexOf('(');
if (parameterListStart > -1)
{
parameterTypeNames = methodOrTypeName.Substring(parameterListStart).Trim('(', ')').Split(',');
methodOrTypeName = methodOrTypeName.Substring(0, parameterListStart);
}
var candidates = compilation.GetMembers(methodOrTypeName);
Assert.Equal(parameterTypeNames == null, candidates.Length == 1);
Symbol methodOrType = null;
foreach (var candidate in candidates)
{
methodOrType = candidate;
if ((parameterTypeNames == null) ||
parameterTypeNames.SequenceEqual(methodOrType.GetParameters().Select(p => p.Type.Name)))
{
// Found a match.
break;
}
}
Assert.False(methodOrType == null, "Could not find method or type with signature '" + signature + "'.");
return methodOrType;
}