public IEnumerable <MethodSpecifier> GetPublicMethodOverloads(MethodSpecifier methodSpecifier) { ITypeSymbol type = GetTypeFromSpecifier(methodSpecifier.DeclaringType); // TODO: Get a better way to determine is a method specifier is an operator. bool isOperator = methodSpecifier.Name.StartsWith("op_"); if (type != null) { return(type.GetMethods() .Where(m => m.Name == methodSpecifier.Name && m.IsPublic() && m.IsStatic == methodSpecifier.Modifiers.HasFlag(MethodModifiers.Static) && (isOperator ? (m.MethodKind == MethodKind.BuiltinOperator || m.MethodKind == MethodKind.UserDefinedOperator) : 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 <MethodSpecifier> GetPublicStaticFunctionsForType(TypeSpecifier typeSpecifier) { ITypeSymbol type = GetTypeFromSpecifier(typeSpecifier); if (type != null) { // Get all public static methods, ignore special ones (properties / events), // ignore those with generic parameters since we cant set those yet return(type.GetMethods() .Where(m => m.IsPublic() && !m.IsStatic && !m.IsGenericMethod && m.MethodKind == MethodKind.Ordinary || m.MethodKind == MethodKind.BuiltinOperator || m.MethodKind == MethodKind.UserDefinedOperator) .OrderBy(m => m.ContainingNamespace?.Name) .ThenBy(m => m.ContainingType?.Name) .ThenBy(m => m.Name) .Select(m => ReflectionConverter.MethodSpecifierFromSymbol(m))); } else { return(new MethodSpecifier[] { }); } }
public IEnumerable <MethodSpecifier> GetPublicMethodOverloads(MethodSpecifier methodSpecifier) { ITypeSymbol type = GetTypeFromSpecifier(methodSpecifier.DeclaringType); if (type != null) { // TODO: Handle generic methods instead of just ignoring them return(type.GetMethods() .Where(m => m.Name == methodSpecifier.Name && m.IsPublic() && m.IsStatic == methodSpecifier.Modifiers.HasFlag(MethodModifiers.Static) && !m.IsGenericMethod && m.MethodKind == MethodKind.Ordinary || m.MethodKind == MethodKind.BuiltinOperator || m.MethodKind == MethodKind.UserDefinedOperator) .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 <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]); } }