make() public method

public make ( ) : object
return object
示例#1
0
        public static UriScheme find(string scheme, bool check)
        {
            // check cache
            lock (m_cache)
            {
                UriScheme cached = (UriScheme)m_cache[scheme];
                if (cached != null)
                {
                    return(cached);
                }
            }

            try
            {
                // lookup scheme type (avoid building index for common types)
                Type t = null;
                if (scheme == "fan")
                {
                    t = Sys.FanSchemeType;
                }
                if (scheme == "file")
                {
                    t = Sys.FileSchemeType;
                }
                if (t == null)
                {
                    string qname = (string)Env.cur().index("sys.uriScheme." + scheme).first();
                    if (qname == null)
                    {
                        throw UnresolvedErr.make().val;
                    }
                    t = Type.find(qname);
                }

                // allocate instance
                UriScheme s = (UriScheme)t.make();
                s.m_scheme = scheme;

                // add to cache
                lock (m_cache)
                {
                    UriScheme cached = (UriScheme)m_cache[scheme];
                    if (cached != null)
                    {
                        return(cached);
                    }
                    m_cache[scheme] = s;
                }

                return(s);
            }
            catch (UnresolvedErr.Val) {}
            catch (System.Exception e) { Err.dumpStack(e); }

            if (!check)
            {
                return(null);
            }
            throw UnresolvedErr.make("Unknown scheme: " + scheme).val;
        }
示例#2
0
文件: Facets.cs 项目: nomit007/f4
        public Facet decode(Type type, string s)
        {
            try
              {
            // if no string use make/defVal
            if (s.Length == 0) return (Facet)type.make();

            // decode using normal Fantom serialization
            return (Facet)ObjDecoder.decode(s);
              }
              catch (System.Exception e)
              {
            string msg = "ERROR: Cannot decode facet " + type + ": " + s;
            System.Console.WriteLine(msg);
            Err.dumpStack(e);
            m_map.Remove(type);
            throw IOErr.make(msg).val;
              }
        }
示例#3
0
文件: Facets.cs 项目: syatanic/fantom
        public Facet decode(Type type, string s)
        {
            try
            {
                // if no string use make/defVal
                if (s.Length == 0)
                {
                    return((Facet)type.make());
                }

                // decode using normal Fantom serialization
                return((Facet)ObjDecoder.decode(s));
            }
            catch (System.Exception e)
            {
                string msg = "ERROR: Cannot decode facet " + type + ": " + s;
                System.Console.WriteLine(msg);
                Err.dumpStack(e);
                m_map.Remove(type);
                throw IOErr.make(msg).val;
            }
        }
示例#4
0
文件: Fan.cs 项目: syatanic/fantom
        static int callMain(Type t, Method m)
        {
            // check parameter type and build main arguments
            List args;
            List pars = m.@params();

            if (pars.sz() == 0)
            {
                args = null;
            }
            else if (((Param)pars.get(0)).type().@is(Sys.StrType.toListOf()) &&
                     (pars.sz() == 1 || ((Param)pars.get(1)).hasDefault()))
            {
                args = new List(Sys.ObjType, new object[] { Env.cur().args() });
            }
            else
            {
                System.Console.WriteLine("ERROR: Invalid parameters for main: " + m.signature());
                return(-1);
            }

            // invoke
            try
            {
                if (m.isStatic())
                {
                    return(toResult(m.callList(args)));
                }
                else
                {
                    return(toResult(m.callOn(t.make(), args)));
                }
            }
            catch (Err.Val ex)
            {
                ex.err().trace();
                return(-1);
            }
        }
示例#5
0
文件: Fant.cs 项目: nomit007/f4
        private int runTest(Type type, Method method)
        {
            Method setup    = type.method("setup", true);
              Method teardown = type.method("teardown", true);

              FanSysTest test = null;
              List args = null;
              try
              {
            test = (FanSysTest)type.make();
            args = new List(Sys.ObjType, new object[] {test});
              }
              catch (System.Exception e)
              {
            System.Console.WriteLine();
            System.Console.WriteLine("ERROR: Cannot make test " + type);
            if (e is Err.Val)
              ((Err.Val)e).err().trace();
            else
              Err.dumpStack(e);
            return -1;
              }

              try
              {
            test.m_curTestMethod = method;
            setup.callList(args);
            method.callList(args);
            return test.verifyCount;
              }
              catch (System.Exception e)
              {
            //System.Console.WriteLine(" -- " + e.GetType() + " -- ");
            System.Console.WriteLine();
            System.Console.WriteLine("TEST FAILED");
            if (e is Err.Val)
              ((Err.Val)e).err().trace();
            else
              Err.dumpStack(e);
            return -1;
              }
              finally
              {
            try
            {
              if (args != null) teardown.callList(args);
            }
            catch (System.Exception e)
            {
              Err.dumpStack(e);
            }
            test.m_curTestMethod = null;
              }
        }
示例#6
0
文件: Fan.cs 项目: xored/f4
        static int callMain(Type t, Method m)
        {
            // check parameter type and build main arguments
              List args;
              List pars = m.@params();
              if (pars.sz() == 0)
              {
            args = null;
              }
              else if (((Param)pars.get(0)).type().@is(Sys.StrType.toListOf()) &&
               (pars.sz() == 1 || ((Param)pars.get(1)).hasDefault()))
              {
            args = new List(Sys.ObjType, new object[] { Env.cur().args() });
              }
              else
              {
            System.Console.WriteLine("ERROR: Invalid parameters for main: " + m.signature());
            return -1;
              }

              // invoke
              try
              {
            if (m.isStatic())
              return toResult(m.callList(args));
            else
              return toResult(m.callOn(t.make(), args));
              }
              catch (Err.Val ex)
              {
            ex.err().trace();
            return -1;
              }
        }