Ejemplo n.º 1
0
        public static List <GeometryEndPoint> Create(Type t)
        {
            List <GeometryEndPoint> endpoints = new List <GeometryEndPoint>();

            if (!t.IsAbstract)
            {
                var constructors = t.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
                if (constructors != null && constructors.Length > 0)
                {
                    GeometryEndPoint endpoint = new GeometryEndPoint(t, constructors);
                    endpoints.Add(endpoint);
                }
            }

            var methods    = t.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static);
            var methodlist = new List <MethodInfo>(methods);

            methodlist.Sort((a, b) => a.Name.CompareTo(b.Name));
            for (int i = 0; i < methodlist.Count; i++)
            {
                string funcname  = methodlist[i].Name;
                var    overloads = new List <MethodInfo>();
                overloads.Add(methodlist[i]);
                for (int j = i + 1; j < methodlist.Count; j++)
                {
                    if (funcname.Equals(methodlist[j].Name))
                    {
                        i = j;
                        overloads.Add(methodlist[i]);
                        continue;
                    }
                    break;
                }

                // This is the general "catch all" endpoint that attempts to figure out the best routine to call
                GeometryEndPoint endpoint = new GeometryEndPoint(t, overloads.ToArray());
                endpoints.Add(endpoint);

                foreach (var overload in overloads)
                {
                    var parameters = overload.GetParameters();
                    if (parameters == null || parameters.Length < 1)
                    {
                        continue;
                    }
                    endpoints.Add(new GeometryEndPoint(t, overload));
                }
            }

            return(endpoints);
        }
Ejemplo n.º 2
0
 private static IEnumerable <GeometryEndPoint> CreateEndpoints(Assembly assembly, string nameSpace)
 {
     foreach (var export in assembly.GetExportedTypes())
     {
         if (!string.Equals(export.Namespace, nameSpace, StringComparison.Ordinal))
         {
             continue;
         }
         if (export.IsInterface || export.IsEnum)
         {
             continue;
         }
         if (export.IsClass || export.IsValueType)
         {
             var endpoints = GeometryEndPoint.Create(export);
             foreach (var endpoint in endpoints)
             {
                 yield return(endpoint);
             }
         }
     }
 }