本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# NamedTypeSymbol.GetMembers方法的具体用法?C# NamedTypeSymbol.GetMembers怎么用?C# NamedTypeSymbol.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol
的用法示例。
在下文中一共展示了NamedTypeSymbol.GetMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitNamedType
public override void VisitNamedType(NamedTypeSymbol symbol)
{
_cancellationToken.ThrowIfCancellationRequested();
var sourceTypeSymbol = symbol as SourceMemberContainerTypeSymbol;
if ((object)sourceTypeSymbol != null)
{
if (_moduleBeingBuilt != null)
{
// In some circumstances (e.g. implicit implementation of an interface method by a non-virtual method in a
// base type from another assembly) it is necessary for the compiler to generate explicit implementations for
// some interface methods. They don't go in the symbol table, but if we are emitting metadata, then we should
// generate MethodDef entries for them.
foreach (var synthesizedExplicitImpl in sourceTypeSymbol.GetSynthesizedExplicitImplementations(_cancellationToken))
{
_moduleBeingBuilt.AddSynthesizedDefinition(symbol, synthesizedExplicitImpl);
}
}
}
foreach (Symbol member in symbol.GetMembers())
{
switch (member.Kind)
{
case SymbolKind.Property:
case SymbolKind.NamedType:
member.Accept(this);
break;
}
}
}
示例2: LoadChildType
private static XElement LoadChildType(NamedTypeSymbol t)
{
XElement elem = new XElement("type");
elem.Add(new XAttribute("name", t.Name));
if (t.Arity > 0)
{
string typeParams = string.Empty;
foreach (var param in t.TypeParameters)
{
if (typeParams.Length > 0)
{
typeParams += ",";
}
typeParams += param.Name;
}
elem.Add(new XAttribute("Of", typeParams));
}
if (t.BaseType != null)
{
elem.Add(new XAttribute("base", t.BaseType.ToTestDisplayString()));
}
var fields = t.GetMembers().Where(m => m.Kind == SymbolKind.Field).OrderBy(f => f.Name).Cast<FieldSymbol>();
elem.Add(from f in fields select LoadField(f));
var childrenTypes = t.GetTypeMembers().OrderBy(c => c, new NameAndArityComparer());
elem.Add(from c in childrenTypes select LoadChildType(c));
return elem;
}
示例3: EmbedMatchingInterfaceMethods
private bool EmbedMatchingInterfaceMethods(NamedTypeSymbol sourceInterface, CSharpSyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics)
{
bool foundMatch = false;
foreach (Symbol m in sourceInterface.GetMembers(UnderlyingEvent.MetadataName))
{
if (m.Kind == SymbolKind.Method)
{
TypeManager.EmbedMethodIfNeedTo((MethodSymbol)m, syntaxNodeOpt, diagnostics);
foundMatch = true;
}
}
return foundMatch;
}
示例4: Property
public BoundExpression Property(NamedTypeSymbol receiver, string name)
{
// TODO: unroll loop and add diagnostics for failure
var property = receiver.GetMembers(name).OfType<PropertySymbol>().Single();
Debug.Assert(property.IsStatic);
return Call(null, property.GetMethod);
}
示例5: CheckInnerClassHelper
private static void CheckInnerClassHelper(NamedTypeSymbol innerClass, string methodName, Symbol interfaceMethod)
{
var @interface = interfaceMethod.ContainingType;
Assert.Equal(1, innerClass.Arity);
Assert.Equal(TypeKind.Class, innerClass.TypeKind);
Assert.Equal(@interface, innerClass.Interfaces.Single().ConstructedFrom);
var innerClassMethod = (MethodSymbol)innerClass.GetMembers(methodName).Single();
var innerClassImplementingMethod = innerClassMethod.ExplicitInterfaceImplementations.Single();
Assert.Equal(interfaceMethod, innerClassImplementingMethod.OriginalDefinition);
Assert.Equal(@interface, innerClassImplementingMethod.ContainingType.ConstructedFrom);
}
示例6: Test01
public Test01()
{
string source = @"
using System.Diagnostics;
[assembly: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
[module: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
class TestClass
{
[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
public int testField;
[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
public int TestProperty
{
[return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
get
{
return testField;
}
}
[return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
public T TestMethod<[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T>
([DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T testParameter)
{
return testParameter;
}
}";
var compilation1 = CSharpCompilation.Create("C1", new[] { Parse(source) }, new[] { OldMsCorLib }, TestOptions.ReleaseDll);
c1 = new CSharpCompilationReference(compilation1);
var c1Assembly = compilation1.Assembly;
var compilation2 = CSharpCompilation.Create("C2", references: new MetadataReference[] { NewMsCorLib, c1 });
c2 = new CSharpCompilationReference(compilation2);
var c1AsmRef = compilation2.GetReferencedAssemblySymbol(c1);
Assert.NotSame(c1Assembly, c1AsmRef);
c1MscorLibAssemblyRef = compilation1.GetReferencedAssemblySymbol(OldMsCorLib);
c2MscorlibAssemblyRef = compilation2.GetReferencedAssemblySymbol(NewMsCorLib);
Assert.NotSame(c1MscorLibAssemblyRef, c2MscorlibAssemblyRef);
oldMsCorLib_systemType = c1MscorLibAssemblyRef.GetTypeByMetadataName("System.Type");
newMsCorLib_systemType = c2MscorlibAssemblyRef.GetTypeByMetadataName("System.Type");
Assert.NotSame(oldMsCorLib_systemType, newMsCorLib_systemType);
oldMsCorLib_debuggerTypeProxyAttributeType = c1MscorLibAssemblyRef.GetTypeByMetadataName("System.Diagnostics.DebuggerTypeProxyAttribute");
newMsCorLib_debuggerTypeProxyAttributeType = c2MscorlibAssemblyRef.GetTypeByMetadataName("System.Diagnostics.DebuggerTypeProxyAttribute");
Assert.NotSame(oldMsCorLib_debuggerTypeProxyAttributeType, newMsCorLib_debuggerTypeProxyAttributeType);
oldMsCorLib_debuggerTypeProxyAttributeCtor = (MethodSymbol)oldMsCorLib_debuggerTypeProxyAttributeType.GetMembers(".ctor").Single(
m => ((MethodSymbol)m).ParameterCount == 1 && ((MethodSymbol)m).ParameterTypes[0] == oldMsCorLib_systemType);
newMsCorLib_debuggerTypeProxyAttributeCtor = (MethodSymbol)newMsCorLib_debuggerTypeProxyAttributeType.GetMembers(".ctor").Single(
m => ((MethodSymbol)m).ParameterCount == 1 && ((MethodSymbol)m).ParameterTypes[0] == newMsCorLib_systemType);
Assert.NotSame(oldMsCorLib_debuggerTypeProxyAttributeCtor, newMsCorLib_debuggerTypeProxyAttributeCtor);
}
示例7: HasSynthesizedStaticConstructor
private static bool HasSynthesizedStaticConstructor(NamedTypeSymbol typeSymbol)
{
foreach (var member in typeSymbol.GetMembers(WellKnownMemberNames.StaticConstructorName))
{
if (member.IsImplicitlyDeclared)
{
return true;
}
}
return false;
}
示例8: VisitNamedType
/// <summary>
/// Write own documentation comments and then descend into members.
/// </summary>
public override void VisitNamedType(NamedTypeSymbol symbol)
{
_cancellationToken.ThrowIfCancellationRequested();
if (_filterTree != null && !symbol.IsDefinedInSourceTree(_filterTree, _filterSpanWithinTree))
{
return;
}
DefaultVisit(symbol);
if (!_isForSingleSymbol)
{
foreach (Symbol member in symbol.GetMembers())
{
_cancellationToken.ThrowIfCancellationRequested();
member.Accept(this);
}
}
}
示例9: CheckPrivateMembers
private void CheckPrivateMembers(NamedTypeSymbol type, bool isFromSource, bool importPrivates)
{
Symbol member;
member = type.GetMembers("Public").SingleOrDefault();
Assert.NotNull(member);
member = type.GetMembers("Internal").SingleOrDefault();
Assert.NotNull(member);
member = type.GetMembers("Protected").SingleOrDefault();
Assert.NotNull(member);
member = type.GetMembers("ProtectedInternal").SingleOrDefault();
Assert.NotNull(member);
member = type.GetMembers("Private").SingleOrDefault();
if (isFromSource || importPrivates)
{
Assert.NotNull(member);
}
else
{
Assert.Null(member);
}
}
示例10: VerifyMethodAndAccessorSame
private void VerifyMethodAndAccessorSame(NamedTypeSymbol type, PropertySymbol property, MethodSymbol accessor)
{
Assert.NotNull(accessor);
Assert.Equal(type, accessor.ContainingType);
Assert.Equal(type, accessor.ContainingSymbol);
var method = type.GetMembers(accessor.Name).Single();
Assert.NotNull(method);
Assert.Equal(accessor, method);
Assert.True(accessor.MethodKind == MethodKind.PropertyGet || accessor.MethodKind == MethodKind.PropertySet,
"Accessor kind: " + accessor.MethodKind.ToString());
Assert.Equal(accessor.AssociatedSymbol, property);
}
示例11: CheckConstantField
private void CheckConstantField(NamedTypeSymbol type, string name, Accessibility declaredAccessibility, SpecialType fieldType, object value)
{
var field = type.GetMembers(name).SingleOrDefault() as FieldSymbol;
Assert.NotNull(field);
Assert.True(field.IsStatic);
Assert.True(field.IsConst);
Assert.Equal(field.DeclaredAccessibility, declaredAccessibility);
Assert.Equal(field.Type.SpecialType, fieldType);
Assert.Equal(field.ConstantValue, value);
}
示例12: CheckInternalMembers
private void CheckInternalMembers(NamedTypeSymbol type, bool isFromSource)
{
Assert.NotNull(type.GetMembers("Public").SingleOrDefault());
var member = type.GetMembers("Internal").SingleOrDefault();
if (isFromSource)
Assert.NotNull(member);
else
Assert.Null(member);
}
示例13: CheckEnumType
private void CheckEnumType(NamedTypeSymbol type, Accessibility declaredAccessibility, SpecialType underlyingType)
{
Assert.Equal(type.BaseType.SpecialType, SpecialType.System_Enum);
Assert.Equal(type.EnumUnderlyingType.SpecialType, underlyingType);
Assert.Equal(type.DeclaredAccessibility, declaredAccessibility);
Assert.True(type.IsSealed);
// value__ field should not be exposed from type, even though it is public,
// since we want to prevent source from accessing the field directly.
var field = type.GetMembers(WellKnownMemberNames.EnumBackingFieldName).SingleOrDefault() as FieldSymbol;
Assert.Null(field);
var sourceType = type as SourceNamedTypeSymbol;
if (sourceType != null)
{
field = sourceType.EnumValueField;
Assert.NotNull(field);
Assert.Equal(field.Name, WellKnownMemberNames.EnumBackingFieldName);
Assert.False(field.IsStatic);
Assert.False(field.IsConst);
Assert.False(field.IsReadOnly);
Assert.Equal(field.DeclaredAccessibility, Accessibility.Public); // Dev10: value__ is public
Assert.Equal(field.Type, type.EnumUnderlyingType);
var module = new PEAssemblyBuilder((SourceAssemblySymbol)sourceType.ContainingAssembly, EmitOptions.Default, OutputKind.DynamicallyLinkedLibrary,
GetDefaultModulePropertiesForSerialization(), SpecializedCollections.EmptyEnumerable<ResourceDescription>());
var context = new EmitContext(module, null, new DiagnosticBag());
var typeDefinition = (Microsoft.Cci.ITypeDefinition)type;
var fieldDefinition = typeDefinition.GetFields(context).First();
Assert.Same(fieldDefinition, field); // Dev10: value__ field is the first field.
Assert.True(fieldDefinition.IsSpecialName);
Assert.True(fieldDefinition.IsRuntimeSpecial);
context.Diagnostics.Verify();
}
}
示例14: CheckEnumConstant
private void CheckEnumConstant(NamedTypeSymbol type, string name, object value)
{
var field = type.GetMembers(name).SingleOrDefault() as FieldSymbol;
Assert.NotNull(field);
Assert.True(field.IsStatic);
Assert.True(field.IsConst);
// TODO: DeclaredAccessibility should be NotApplicable.
//Assert.Equal(field.DeclaredAccessibility, Accessibility.NotApplicable);
Assert.Equal(field.Type, type);
Assert.Equal(field.ConstantValue, value);
var sourceType = type as SourceNamedTypeSymbol;
if (sourceType != null)
{
var fieldDefinition = (Microsoft.Cci.IFieldDefinition)field;
Assert.False(fieldDefinition.IsSpecialName);
Assert.False(fieldDefinition.IsRuntimeSpecial);
}
}
示例15: FindIndexerWithParameterCount
private static PropertySymbol FindIndexerWithParameterCount(NamedTypeSymbol type, int parameterCount)
{
return type.GetMembers().Where(s => s.Kind == SymbolKind.Property).Cast<PropertySymbol>().Where(p => p.Parameters.Length == parameterCount).Single();
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:4,代码来源:RetargetExplicitInterfaceImplementation.cs