private IMethodSymbol GetMethodInfoFromSpecifier(MethodSpecifier specifier) { INamedTypeSymbol declaringType = GetTypeFromSpecifier <INamedTypeSymbol>(specifier.DeclaringType); return(declaringType?.GetMethods().FirstOrDefault( m => m.Name == specifier.Name && m.Parameters.Select(p => ReflectionConverter.BaseTypeSpecifierFromSymbol(p.Type)).SequenceEqual(specifier.ArgumentTypes))); }
public IEnumerable <TypeSpecifier> GetNonStaticTypes() { return(GetValidTypes().Where( t => t.IsPublic() && !(t.IsAbstract && t.IsSealed)) .OrderBy(t => t.ContainingNamespace?.Name) .ThenBy(t => t.Name) .Select(t => ReflectionConverter.TypeSpecifierFromSymbol(t))); }
public IEnumerable <ConstructorSpecifier> GetConstructors(TypeSpecifier typeSpecifier) { var symbol = GetTypeFromSpecifier <INamedTypeSymbol>(typeSpecifier); if (symbol != null) { return(symbol.Constructors.Select(c => ReflectionConverter.ConstructorSpecifierFromSymbol(c))); } return(new ConstructorSpecifier[0]); }
public IEnumerable <PropertySpecifier> GetPublicStaticProperties() { return(GetValidTypes() .Where(t => t.IsPublic() && !t.IsGenericType) .SelectMany(t => t.GetMembers() .Where(m => m.Kind == SymbolKind.Property) .Cast <IPropertySymbol>() .Where(p => p.IsStatic && p.IsPublic() && !p.IsAbstract) .OrderBy(p => p.ContainingNamespace?.Name) .ThenBy(p => p.ContainingType?.Name) .ThenBy(p => p.Name) .Select(p => ReflectionConverter.PropertySpecifierFromSymbol(p)))); }
public IEnumerable <MethodSpecifier> GetStaticFunctionsWithArgumentType(TypeSpecifier searchTypeSpec) { // Find all public static methods IEnumerable <IMethodSymbol> availableMethods = GetValidTypes() .Where(t => t.IsPublic()) .SelectMany(t => t.GetMethods() .Where(m => m.IsPublic() && m.IsStatic && !m.ContainingType.IsUnboundGenericType)) .OrderBy(m => m?.ContainingNamespace.Name) .ThenBy(m => m?.ContainingType.Name) .ThenBy(m => m.Name); ITypeSymbol searchType = GetTypeFromSpecifier(searchTypeSpec); List <MethodSpecifier> foundMethods = new List <MethodSpecifier>(); // Find compatible methods foreach (IMethodSymbol availableMethod in availableMethods) { MethodSpecifier availableMethodSpec = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod); // Check each argument whether it can be replaced by the wanted type for (int i = 0; i < availableMethodSpec.Arguments.Count; i++) { ITypeSymbol argType = availableMethod.Parameters[i].Type; BaseType arg = ReflectionConverter.BaseTypeSpecifierFromSymbol(argType); if (arg == searchTypeSpec || searchType.IsSubclassOf(argType)) { MethodSpecifier foundMethod = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod); foundMethod = TryMakeClosedMethod(foundMethod, arg, searchTypeSpec); // Only add fully closed methods if (foundMethod != null && !foundMethods.Contains(foundMethod)) { foundMethods.Add(foundMethod); } } } } return(foundMethods); }
public IEnumerable <MethodSpecifier> GetStaticFunctions() { return(GetValidTypes() .Where(t => t.IsPublic() && !t.IsGenericType) .SelectMany(t => t.GetMethods() .Where(m => m.IsStatic && m.IsPublic() && m.Parameters.All(p => p.Type.TypeKind != TypeKind.TypeParameter) && m.ReturnType.TypeKind != TypeKind.TypeParameter && !m.IsGenericMethod && !m.ContainingType.IsUnboundGenericType) .OrderBy(m => m.ContainingNamespace?.Name) .ThenBy(m => m.ContainingType?.Name) .ThenBy(m => m.Name) .Select(m => ReflectionConverter.MethodSpecifierFromSymbol(m)))); }
public IEnumerable <MethodSpecifier> GetOverridableMethodsForType(TypeSpecifier typeSpecifier) { ITypeSymbol type = GetTypeFromSpecifier(typeSpecifier); if (type != null) { // Get all overridable methods, ignore special ones (properties / events) return(type.GetMethods() .Where(m => (m.IsVirtual || m.IsOverride || m.IsAbstract) && m.MethodKind == MethodKind.Ordinary) .OrderBy(m => m.ContainingNamespace?.Name) .ThenBy(m => m.ContainingType?.Name) .ThenBy(m => m.Name) .Select(m => ReflectionConverter.MethodSpecifierFromSymbol(m))); } else { return(new MethodSpecifier[0]); } }
public IEnumerable <PropertySpecifier> GetPublicPropertiesForType(TypeSpecifier typeSpecifier) { var members = GetTypeFromSpecifier(typeSpecifier) .GetAllMembers(); var properties = members .Where(m => m.Kind == SymbolKind.Property) .Cast <IPropertySymbol>() .OrderBy(p => p.ContainingNamespace?.Name) .ThenBy(p => p.ContainingType?.Name) .ThenBy(p => p.Name) .Select(p => ReflectionConverter.PropertySpecifierFromSymbol(p)); // TODO: Move variables to seperate function / unify properties and variables in a better way. return(properties.Concat(members .Where(m => m.Kind == SymbolKind.Field) .Cast <IFieldSymbol>() .OrderBy(f => f.ContainingNamespace?.Name) .ThenBy(f => f.ContainingType?.Name) .ThenBy(f => f.Name) .Select(f => ReflectionConverter.PropertySpecifierFromField(f)) )); }
public IEnumerable <ConstructorSpecifier> GetConstructors(TypeSpecifier typeSpecifier) { return(GetTypeFromSpecifier <INamedTypeSymbol>(typeSpecifier)?.Constructors.Select(c => ReflectionConverter.ConstructorSpecifierFromSymbol(c))); }