public override DynamicSupport HasMethod(string name, out NamedData <Type>[] parameters, out Type returnType)
 {
     parameters = null;
     returnType = null;
     if (m_initialized)
     {
         if (name == "Anderson")
         {
             parameters = new NamedData <Type>[]
             {
                 new NamedData <Type>("a", typeof(long)),
                 new NamedData <Type>("b", typeof(string)),
                 new NamedData <Type>("c", typeof(TimeSpan))
             };
             returnType = typeof(long);
             return(DynamicSupport.Yes);
         }
         else if (name == "Bengtson")
         {
             parameters = new NamedData <Type>[]
             {
                 new NamedData <Type>("g", typeof(Identifier)),
                 new NamedData <Type>("h", typeof(long))
             };
             returnType = typeof(bool);
             return(DynamicSupport.Yes);
         }
         else if (name == "Christianson")
         {
             parameters = new NamedData <Type>[] { };
             returnType = typeof(Identifier);
             return(DynamicSupport.Yes);
         }
         else if (name == "Dengson")
         {
             parameters = new NamedData <Type>[]
             {
                 new NamedData <Type>("n", typeof(string)),
                 new NamedData <Type>("q", typeof(long))
             };
             returnType = typeof(string[]);
             return(DynamicSupport.Yes);
         }
         else if (name == "Esildro")
         {
             parameters = new NamedData <Type>[] { };
             returnType = typeof(void);
             return(DynamicSupport.Yes);
         }
         else
         {
             return(DynamicSupport.No);
         }
     }
     else
     {
         return(DynamicSupport.KnownAtRuntimeOnly);
     }
 }
Exemplo n.º 2
0
        private NamedData <Tuple <List <IScriptFile>, IReadOnlyCollection <IScriptFile> > > CreateNewList(string @namespace)
        {
            var newlist = new List <IScriptFile>();
            var list    = new NamedData <Tuple <List <IScriptFile>, IReadOnlyCollection <IScriptFile> > >(
                @namespace,
                new Tuple <List <IScriptFile>, IReadOnlyCollection <IScriptFile> >(
                    newlist,
                    newlist.AsReadOnly()));

            m_namespaceLists.Add(list);
            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Runs example
        /// </summary>
        /// <param name="unused">Unused command line arguments</param>
        static void Main(string[] unused)
        {
            Console.WriteLine("Beginning code generation...");
            Console.WriteLine();
            Console.WriteLine();


            // Create template renderer
            var mustache = new MustacheRenderer();


            // Select all types with NameAttribute
            AppDomain.CurrentDomain
            .GetAssemblies()
            .SelectMany(a => a.GetTypes())
            .Where(t => t.HasAttribute <NameAttribute>(false))
            .ToList()

            // For each type with NameAttribute
            // 1. prepare template data, and
            // 2. render it
            .ForEach(t =>
            {
                var template = NamedTemplate;
                var data     = new NamedData
                {
                    Namespace = t.Namespace,
                    ClassName = t.Name,
                    Name      = t.GetAttribute <NameAttribute>(false).Name
                };

                var code = mustache.Render(template, data, null);

                // Show generated code in console
                Console.WriteLine(string.Format("'INamed' implementation for '{0}':", t.Name));
                Console.WriteLine();
                Console.WriteLine(code);
                Console.WriteLine();
            });


            Console.WriteLine();
            Console.WriteLine("Code generation ran to completion...");
            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }