List of Available Functions - shoff/Flee GitHub Wiki

sbrickler Feb 4, 2008 at 12:54 PM Great Library! I was wondering if there is a way to get a list of all the available functions that can be used in an expression based on the imported types. Maybe I am missing something and it is already there. What I am looking to do is create an "expression builder" type of UI control for my application where the user can select from a list of available method signatures, without having to just remember what is available.


ECiloci Coordinator Feb 5, 2008 at 9:49 PM Sure, I can put some accessor methods on the Imports which will return all the available methods in a particular namespace. I assume that you're fine with getting MethodInfo instances back?


sbrickler Feb 5, 2008 at 10:33 PM Yes, that would be great! On a related note, I am assuming you are using reflection to get type information for expression owners and variables? We often have types in which we use a customtypedescriptor. This allows us to change the view of the instance in the propertygrid control. For instance, we can hide certain properties or add dynamic properties. It may be a good enhancement to use the Typedescriptor object to get the properties of the expression owner or variables. That way expressions can see this changed view of the object. The great thing about Typedescriptor is that if a customtypedescriptor is not found for the type info it will return is the same results as reflection. Of course, you may already be doing this, I haven't had a change to review the source on this.


ECiloci Coordinator Feb 6, 2008 at 9:23 PM Thanks for the tip. That would allow lots of flexibility. I just have to check out how you get the value of a dynamic property. Is it just a static function call on the TypeDescriptor?


sbrickler Feb 6, 2008 at 11:16 PM Typedescriptor works very much like refection. Actually .net data binding uses it. There isn't anything in particular needed to read dynamic properties per-se. Dynamic properties can be created by implement a TypeDescriptonProvider for the type of a CustomTypeDescriptor. Once implemented on the class all is needed is a call to TypeDescriptor.GetProperties and the properties are provided to you as a propertydescriptor object (similar to PropertyInfo). Even If you call Typedescriptor.GetProperties on a class that doesn't have a TypeDescriptionProvider it will just return the properties as reflection would. Here is a great article on implementing dynamic properties:


ECiloci Coordinator Feb 20, 2008 at 9:20 PM Flee-0.9.17.1 now supports nested namespaces and also exposes the various imports of an expression.

Essentially, all imports derive from ImportBase, have an IsContainer property that lets you know whether it contains other imports, and a GetMembers function that retrieves all of the imports' members.

The ImportsCollection exposes the root import which you could pass to the following function to print out the imports tree:

#3E62A6; font-family:Consolas,Courier New,Courier,Monospace; font-size:1em; margin-top:0; padding:.5em; height:auto; overflow:auto; overflow-x:auto; overflow-y:auto">private void PrintImportMembers(ImportBase import, int level) 
{ 
    string indent = new string(" ", level * 4); 
    
    if (import.IsContainer == true) { 
        Console.Write(indent); 
        Console.WriteLine("===={0}===", import.Name); 
    } 
    
    MemberInfo[] members = import.GetMembers(MemberTypes.Method); 
    
    foreach (MemberInfo mi in members) { 
        Console.Write(indent); 
        Console.WriteLine(mi); 
    } 
    
    foreach (ImportBase childImport in import) { 
        PrintImportMembers(childImport, level + 1); 
    } 
}

I haven't put in the doc comments yet but this should get you started


sbrickler Feb 20, 2008 at 11:50 PM

Thanks! That worked great! I have already updated my code.