List of available functions

Feb 4, 2008 at 6:54 PM
Great Library! I was wondering if there is a way to get a list of all the avialable 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.
Coordinator
Feb 6, 2008 at 3:49 AM
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?
Feb 6, 2008 at 4:33 AM
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. :)
Coordinator
Feb 7, 2008 at 3:23 AM
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?
Feb 7, 2008 at 5:16 AM
Typedescriptor works very much like refection. Actually .net databinding 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 ahve a TypeDescriptionProvider it will just return the properties as reflection would. Here is a great article on implementing dynamic properties:

http://msdn.microsoft.com/msdnmag/issues/05/05/NETMatters/
Coordinator
Feb 21, 2008 at 3:20 AM
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:

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
Feb 21, 2008 at 5:50 AM
Thanks!
That worked great! I have already updated my code.