Ejemplo n.º 1
0
 // _addNamespacesAndTypes builds a tree of ExpandoObjects representing
 // .NET namespaces, with TypeModel objects at the leaves.  Though Sympl is
 // case-insensitive, we store the names as they appear in .NET reflection
 // in case our globals object or a namespace object gets passed as an IDO
 // to another language or library, where they may be looking for names
 // case-sensitively using EO's default lookup.
 //
 public void AddAssemblyNamesAndTypes()
 {
     foreach (var assm in _assemblies)
     {
         foreach (var typ in assm.GetExportedTypes())
         {
             string[] names = typ.FullName.Split('.');
             var      table = _globals;
             for (int i = 0; i < names.Length - 1; i++)
             {
                 string name = names[i].ToLower();
                 if (DynamicObjectHelpers.HasMember(
                         (IDynamicMetaObjectProvider)table, name))
                 {
                     // Must be Expando since only we have put objs in
                     // the tables so far.
                     table = (ExpandoObject)(DynamicObjectHelpers
                                             .GetMember(table, name));
                 }
                 else
                 {
                     var tmp = new ExpandoObject();
                     DynamicObjectHelpers.SetMember(table, name, tmp);
                     table = tmp;
                 }
             }
             DynamicObjectHelpers.SetMember(table, names[names.Length - 1],
                                            new TypeModel(typ));
         }
     }
 }
Ejemplo n.º 2
0
        public void AddInstanceObjectNamesAndTypes()
        {
            foreach (var instanceObject in _instanceObjects)
            {
                foreach (var methodName in instanceObject.GetType().GetMethods())
                {
                    var table = _globals;
                    if (DynamicObjectHelpers.HasMember(table, instanceObject.GetType().Name))
                    {
                        table = (ExpandoObject)(DynamicObjectHelpers.GetMember(table, instanceObject.GetType().Name));
                    }
                    else
                    {
                        var tmp = new ExpandoObject();
                        DynamicObjectHelpers.SetMember(table, instanceObject.GetType().Name, tmp);
                        table = tmp;
                    }

                    DynamicObjectHelpers.SetMember(table, methodName.Name, instanceObject);
                }
            }
        }