xsharp.eu • Xbase++ forum - Page 4
Page 4 of 4

Re: Xbase++ forum

Posted: Wed Jun 19, 2024 8:05 am
by robert
The following code returns what you want.
Explanation:
- The X# compiler creates a special class that contains the functions, procedures and globals in an assembly
- The X# compiler adds a special attribute to each assembly that it produces.
- This attribute is of the type XSharp.Internal.ClassLibraryAttribute
- This attribute has a field GlobalClassName which contains the name of the (compiler generated) class
- The code below walks all assemblies and checks to see if the assembly has the attribute. This will exclude non X# assemblies
- When it has the attribute, then it retrieves the name of the compiler generated class
- Then it retrieves the type information for that class (an object of System.Type)
- Then it retrieves the names of the public static methods inside that class (an array of MethodInfo objects)
- Then it gets the name of each function

Since functions can be overloaded in X# I have added a check to prevent duplicate names in the list
Function names will NOT be uppercased in the result, but will be retrieved the way that they are stored inside the assembly.
In my test program with XSharp.Core, XSharp.RT and XSharp.XPP this returns over 1000 functions.
I hope this helps

Robert


Code: Select all

USING System.Reflection
USING System
USING System.Linq
USING System.Collections.Generic
USING XSharp.Internal

FUNCTION Start( ) AS VOID
	VAR functions := GetFunctions()
	? functions:Count
	WAIT
	FOREACH VAR f IN functions
	    ? f
	NEXT
	WAIT
RETURN



FUNCTION GetFunctions() AS List<STRING>
    VAR cla := TYPEOF( ClassLibraryAttribute )
    VAR result := List<STRING>{}
    FOREACH asm AS Assembly IN AppDomain.CurrentDomain:GetAssemblies()
        IF ! asm:IsDefined(TYPEOF( ClassLibraryAttribute ), FALSE)
            LOOP
        ENDIF
        VAR atr     := (ClassLibraryAttribute) asm:GetCustomAttributes(cla,FALSE)[1]
        VAR oType := asm:GetType(atr:GlobalClassName,FALSE, TRUE)
        VAR bf := BindingFlags.Static | BindingFlags.Public
        VAR methods := oType:GetMethods(bf)
        FOREACH VAR mi IN methods
            IF ! result:Contains(mi:Name)
                result:Add(mi:Name)
            ENDIF
        NEXT
    NEXT
    RETURN result



Re: Xbase++ forum

Posted: Wed Jun 19, 2024 11:29 am
by DenGhostYY
Thank you very much