当前位置: 首页>>代码示例>>C#>>正文


C# ISeq.count方法代码示例

本文整理汇总了C#中ISeq.count方法的典型用法代码示例。如果您正苦于以下问题:C# ISeq.count方法的具体用法?C# ISeq.count怎么用?C# ISeq.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISeq的用法示例。


在下文中一共展示了ISeq.count方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MacroexpandSeq1

        private static object MacroexpandSeq1(ISeq form)
        {
            object op = RT.first(form);

            if (IsSpecial(op))
                return form;

            // macro expansion
            Var v = IsMacro(op);
            if (v != null)
            {
                try
                {
                    Var.pushThreadBindings(RT.map(RT.MACRO_META, RT.meta(form)));
                    return v.applyTo(form.next());
                }
                finally
                {
                    Var.popThreadBindings();
                }
            }
            else
            {
                if (op is Symbol)
                {
                    Symbol sym = (Symbol)op;
                    string sname = sym.Name;
                    // (.substring s 2 5) => (. x substring 2 5)
                    if (sname[0] == '.')
                    {
                        if (form.count() < 2)
                            throw new ArgumentException("Malformed member expression, expecting (.member target ...)");
                        Symbol method = Symbol.intern(sname.Substring(1));
                        // TODO:  Figure out why the following change made in Java Rev 1158 breaks ants.clj
                        // Note on that revision: force instance member interpretation of (.method ClassName), e.g. (.getMethods String) works
                        //  However, when I do this, it makes ants.clj choke on: (def white-brush (new SolidBrush (.White Color)))
                        object target = RT.second(form);
                        if (MaybeType(target, false) != null)
                            //target = RT.list(IDENTITY, target);
                            target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY, CLASS));
                        return RT.listStar(DOT, target, method, form.next().next());
                        // safe substitute: return RT.listStar(Compiler.DOT, RT.second(form), method, form.next().next());
                    }
                    else if (NamesStaticMember(sym))
                    {
                        Symbol target = Symbol.intern(sym.Namespace);
                        Type t = MaybeType(target, false);
                        if (t != null)
                        {
                            Symbol method = Symbol.intern(sym.Name);
                            return RT.listStar(Compiler.DOT, target, method, form.next());
                        }
                    }
                    else
                    {
                        // (x.substring 2 5) =>  (. s substring 2 5)
                        int index = sname.LastIndexOf('.');
                        if (index == sname.Length - 1)
                            return RT.listStar(Compiler.NEW, Symbol.intern(sname.Substring(0, index)), form.next());
                    }
                }

            }
            return form;
        }
开发者ID:starapor,项目名称:clojure-clr,代码行数:65,代码来源:Compiler.cs

示例2: MacroexpandSeq1

        private static object MacroexpandSeq1(ISeq form)
        {
            object op = RT.first(form);

            if (IsSpecial(op))
                return form;

            // macro expansion
            Var v = IsMacro(op);
            if (v != null)
            {
                // TODO: Check this against current code
                return v.applyTo(RT.cons(form, RT.cons(LOCAL_ENV.get(), form.next())));
            }
            else
            {
                if (op is Symbol)
                {
                    Symbol sym = (Symbol)op;
                    string sname = sym.Name;
                    // (.substring s 2 5) => (. x substring 2 5)
                    if (sname[0] == '.')
                    {
                        if (form.count() < 2)
                            throw new ArgumentException("Malformed member expression, expecting (.member target ...)");
                        Symbol method = Symbol.intern(sname.Substring(1));
                        object target = RT.second(form);
                        if (HostExpr.MaybeType(target, false) != null)
                            target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY, CLASS));
                        // We need to make sure source information gets transferred
                        return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(DOT, target, method, form.next().next())), form);
                    }
                    else if (NamesStaticMember(sym))
                    {
                        Symbol target = Symbol.intern(sym.Namespace);
                        Type t = HostExpr.MaybeType(target, false);
                        if (t != null)
                        {
                            Symbol method = Symbol.intern(sym.Name);
                            // We need to make sure source information gets transferred
                            return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(Compiler.DOT, target, method, form.next())), form);
                        }
                    }
                    else
                    {
                        // (x.substring 2 5) =>  (. x substring 2 5)
                        // also (package.class.name ... ) (. package.class name ... )
                        int index = sname.LastIndexOf('.');
                        if (index == sname.Length - 1)
                            // We need to make sure source information gets transferred
                            return MaybeTransferSourceInfo(RT.listStar(Compiler.NEW, Symbol.intern(sname.Substring(0, index)), form.next()), form);
                    }
                }

            }
            return form;
        }
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:57,代码来源:Compiler.cs

示例3: MacroexpandSeq1

        private static object MacroexpandSeq1(ISeq form)
        {
            object op = RT.first(form);

            if (IsSpecial(op))
                return form;

            // macro expansion
            Var v = IsMacro(op);
            if (v != null)
            {
                try
                {
                    return v.applyTo(RT.cons(form, RT.cons(LocalEnvVar.get(), form.next())));
                }
                catch (ArityException e)
                {
                    // hide the 2 extra params for a macro
                    throw new ArityException(e.Actual - 2, e.Name);
                }
            }
            else
            {
                Symbol sym = op as Symbol;
                if (sym != null)
                {
                    string sname = sym.Name;
                    // (.substring s 2 5) => (. x substring 2 5)
                    if (sname[0] == '.')
                    {
                        if (form.count() < 2)
                            throw new ArgumentException("Malformed member expression, expecting (.member target ...)");
                        Symbol method = Symbol.intern(sname.Substring(1));
                        object target = RT.second(form);
                        if (HostExpr.MaybeType(target, false) != null)
                            target = ((IObj)RT.list(IdentitySym, target)).withMeta(RT.map(RT.TagKey, ClassSym));
                        // We need to make sure source information gets transferred
                        return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(DotSym, target, method, form.next().next())), form);
                    }
                    else if (NamesStaticMember(sym))
                    {
                        Symbol target = Symbol.intern(sym.Namespace);
                        Type t = HostExpr.MaybeType(target, false);
                        if (t != null)
                        {
                            Symbol method = Symbol.intern(sym.Name);
                            // We need to make sure source information gets transferred
                            return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(Compiler.DotSym, target, method, form.next())), form);
                        }
                    }
                    else
                    {
                        // (x.substring 2 5) =>  (. x substring 2 5)
                        // also (package.class.name ... ) (. package.class name ... )
                        int index = sname.LastIndexOf('.');
                        if (index == sname.Length - 1)
                            // We need to make sure source information gets transferred
                            return MaybeTransferSourceInfo(RT.listStar(Compiler.NewSym, Symbol.intern(sname.Substring(0, index)), form.next()), form);
                    }
                }

            }
            return form;
        }
开发者ID:rvedam,项目名称:clojure-clr,代码行数:64,代码来源:Compiler.cs

示例4: GenerateIfExpr

        private static Expression GenerateIfExpr(ISeq form)
        {
            if (form.count() > 4)
                throw new Exception("Too many arguments to if");

            if (form.count() < 3)
                throw new Exception("Too few arguments to if");

            object test = RT.second(form);
            object trueClause = RT.third(form);
            object falseClause = RT.fourth(form);

            // TODO: if test has Boolean type, no need to box, just test directly.
            Expression realExpr = Expression.Call(Method_RT_IsTrue, MaybeBox(Generate(test)));
            Expression thenExpr = Generate(trueClause);
            Expression elseExpr = Generate(falseClause);

            if (thenExpr.Type != elseExpr.Type)
            {
                // Try to reconcile
                if (thenExpr.Type.IsAssignableFrom(elseExpr.Type) && elseExpr.Type != typeof(void))
                    elseExpr = Expression.Convert(elseExpr, thenExpr.Type);
                else if (elseExpr.Type.IsAssignableFrom(thenExpr.Type) && thenExpr.Type != typeof(void))
                    thenExpr = Expression.Convert(thenExpr, elseExpr.Type);
                else
                {
                    if (thenExpr.Type == typeof(void))
                        thenExpr = Expression.Block(thenExpr, Expression.Default(elseExpr.Type));
                    else if (elseExpr.Type == typeof(void))
                        elseExpr = Expression.Block(elseExpr, Expression.Default(thenExpr.Type));
                    else
                    {
                        // TODO: Can we find a common ancestor?  probably not.
                        thenExpr = Expression.Convert(thenExpr, typeof(object));
                        elseExpr = Expression.Convert(elseExpr, typeof(object));
                    }
                }
            }
            return Expression.Condition(realExpr, thenExpr, elseExpr);
        }
开发者ID:kmartin,项目名称:clojure-contrib,代码行数:40,代码来源:Generator.cs

示例5: GenerateHostExpr

        private static Expression GenerateHostExpr(ISeq form)
        {
            // form is one of:
            //  (. x fieldname-sym)
            //  (. x 0-ary-method)
            //  (. x propertyname-sym)
            //  (. x methodname-sym args+)
            //  (. x (methodname-sym args?))
            if (RT.Length(form) < 3)
                throw new ArgumentException("Malformed member expression, expecting (. target member ... )");
            // determine static or instance
            // static target must be symbol, either fully.qualified.Typename or Typename that has been imported
            Type t = MaybeType(RT.second(form),false);
            // at this point, t will be non-null if static
            Expression instance = null;
            if (t == null)
                instance = Generate(RT.second(form));

            if (  form.count() == 3 && RT.third(form) is Symbol )
            {
                Symbol sym = (Symbol) RT.third(form);
                if ( t != null )
                {
                    FieldInfo f = t.GetField(sym.Name, BindingFlags.Static | BindingFlags.Public);
                    if (f != null)
                        return Expression.Field(null, f);

                    PropertyInfo p = t.GetProperty(sym.Name, BindingFlags.Static | BindingFlags.Public);
                    if (p != null)
                        return Expression.Property(null, p);
                }
                else
                {
                    // I doubt that this will work.  We will have to do a runtime determination
                    FieldInfo f = instance.Type.GetField(sym.Name, BindingFlags.Instance | BindingFlags.Public);
                    if (f != null)
                        return Expression.Field(instance, f);

                    PropertyInfo p = instance.Type.GetProperty(sym.Name, BindingFlags.Instance | BindingFlags.Public);
                    if (p != null)
                        return Expression.Property(instance, p);
                }
            }

            ISeq call = RT.third(form) is ISeq ? (ISeq)RT.third(form) : RT.next(RT.next(form));

            if (!(RT.first(call) is Symbol))
                throw new ArgumentException("Malformed member exception");

            string methodName = ((Symbol)RT.first(call)).Name;
            int numArgs = call.count() - 1;

            Expression[] args = new Expression[numArgs];
            int i = 0;
            for (ISeq s = call.next(); s != null; s = s.next(), i++)
                args[i] = Generate(s.first());

            BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod;

            if (t != null)
                flags |= BindingFlags.Static;
            else
                flags |= BindingFlags.Instance;

            Type targetType = t ?? instance.Type;

            //DEBUG:
            //IEnumerable<MethodInfo> einfo1 = targetType.GetMethods();
            //List<MethodInfo> infos1 = new List<MethodInfo>(einfo1);

            IEnumerable<MethodInfo> einfo = targetType.GetMethods(flags).Where(info => info.Name == methodName && info.GetParameters().Length == args.Length);
            List<MethodInfo> infos = new List<MethodInfo>(einfo);

            if (t != null && infos.Count == 0)
                throw new InvalidOperationException(string.Format("No method named: {0} in type: {1}", methodName, targetType.Name));
            else if (infos.Count == 1)
            {
                // TODO: if t is not null, but instance isn't typed, we may be missing overloads.  So I added a t != null.
                // We can improve this when we add better type info propagation.

                // we have a unique match, generate call directly
                if (t != null)
                    return AstUtils.SimpleCallHelper(infos[0], args);
                else
                    //return Expression.Call(instance, infos[0], args);  //asdf-tag
                    return AstUtils.SimpleCallHelper(instance,infos[0], args);
            }
            else
            {
                if (RT.booleanCast(RT.WARN_ON_REFLECTION.deref()))
                {
                    // TODO: use DLR IO
                    ((TextWriter)RT.ERR.deref()).WriteLine(string.Format("Reflection warning, line: {0} - call to {1} can't be resolved.\n", /* line ,*/0, methodName));
                }

                Expression[] moreArgs = new Expression[3];
                moreArgs[0] = Expression.Constant(methodName);
                moreArgs[1] = t != null ? Expression.Constant(t) : instance;
                moreArgs[2] = Expression.NewArrayInit(typeof(object), MaybeBox(args));

//.........这里部分代码省略.........
开发者ID:kmartin,项目名称:clojure-contrib,代码行数:101,代码来源:Generator.cs

示例6: GenerateDefExpr

        private static Expression GenerateDefExpr(ISeq form)
        {
            if (form.count() > 3)
                throw new Exception("Too many arguments to def");

            if (form.count() < 2)
                throw new Exception("Too few arguments to def");

            Symbol sym = RT.second(form) as Symbol;
            bool initProvided = form.count() == 3;

            if (sym == null)
                throw new Exception("Second argument to def must be a Symbol.");

            Var v = lookupVar(sym, true);

            if (v == null)
                throw new Exception("Can't refer to qualified var that doesn't exist");

            if (!v.Namespace.Equals(CurrentNamespace))
            {
                if (sym.Namespace == null)
                    throw new Exception(string.Format("Name conflict, can't def {0} because namespace: {1} refers to: {2}",
                                sym, CurrentNamespace.Name, v));
                else
                    throw new Exception("Can't create defs outside of current namespace");
            }

            IPersistentMap mm = sym.meta();
            // TODO: add source line info metadata.
            //mm = (IPersistentMap) RT.assoc(RT.LINE_KEY, LINE.get()).assoc(RT.FILE_KEY, SOURCE.get());

            // Bizarrely, we don't have to do anything to actually create the var, the lookupVar did that for us.
            // Will this work in a compiled class file?

            List<Expression> exprs = new List<Expression>();

            Expression varExpr = GenerateConstExpr(v);

            if (initProvided)
                exprs.Add(Expression.Call(varExpr, Method_Var_BindRoot, MaybeBox(Generate(RT.third(form))))); ;

            if (mm != null)
                exprs.Add(Expression.Call(varExpr, Method_Var_SetMeta, GenerateMapExpr(mm)));

            exprs.Add(varExpr);

            return Expression.Block(exprs);
        }
开发者ID:kmartin,项目名称:clojure-contrib,代码行数:49,代码来源:Generator.cs

示例7: GenerateAssignExpr

        private static Expression GenerateAssignExpr(ISeq form)
        {
            if (form.count() != 3)
                throw new ArgumentException("Malformed assignment, expecting (set! target val)");

            object target = RT.second(form);
            object init = RT.third(form);

            Var v;

            if ( (v = FindAsVar(target)) != null)
                return GenerateVarAssignExpr(v, init);

            Type t;

            if ((t = FindAsDirectStaticFieldReference(target)) != null)
                return GenerateDirectStaticFieldAssignExpr(t, (target as Symbol).Name, init);

            if ( IsFieldReference(target))
                return GenerateFieldAssignExpr(RT.second((ISeq)target),(string) RT.third((ISeq)target),init);

            throw new ArgumentException("Invalid assignment target");
        }
开发者ID:kmartin,项目名称:clojure-contrib,代码行数:23,代码来源:Generator.cs

示例8: GenerateNewExpr

        private static Expression GenerateNewExpr(ISeq form)
        {
            // form => (new Classname args ... )
            if (form.count() < 2)
                throw new Exception("wrong number of arguments, expecting: (new Classname args ...)");
            Type t = MaybeType(RT.second(form), false);
            if (t == null)
                throw new ArgumentException("Unable to resolve classname: " + RT.second(form));

            int numArgs = form.count() - 2;
            Expression[] args = new Expression[numArgs];
            int i = 0;
            for (ISeq s = RT.next(RT.next(form)); s != null; s = s.next(), i++)
                args[i] = Generate(s.first());

            List<ConstructorInfo> cinfos = new List<ConstructorInfo>(t.GetConstructors().Where(x => x.GetParameters().Length == numArgs && x.IsPublic));

            if (cinfos.Count == 0)
                throw new InvalidOperationException(string.Format("No constructor in type: {0} with {1} arguments", t.Name, numArgs));

            else if (cinfos.Count == 1)
            {
                // we have a unique match, generate directly
                // Need to try to convert the arguments, or the call to Expression.New will choke
                ConstructorInfo info = cinfos[0];
                Expression[] convArgs = new Expression[numArgs];
                for ( i=0; i < numArgs; i++ )
                    convArgs[i] = Expression.Convert(args[i],info.GetParameters()[i].ParameterType);
                return Expression.New(info, convArgs);
            }
            else
            {
                // we must defer to runtime

                if (RT.booleanCast(RT.WARN_ON_REFLECTION.deref()))
                {
                    // TODO: use DLR IO
                    ((TextWriter)RT.ERR.deref()).WriteLine(string.Format("Reflection warning, line: {0} - call to new can't be resolved.\n", /* line ,*/0));
                }

                Expression[] moreArgs = new Expression[2];
                moreArgs[0] = Expression.Constant(t);
                moreArgs[1] = Expression.NewArrayInit(typeof(object), MaybeBox(args));

                return Expression.Call(Method_Reflector_InvokeConstructor, moreArgs);
            }
        }
开发者ID:kmartin,项目名称:clojure-contrib,代码行数:47,代码来源:Generator.cs


注:本文中的ISeq.count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。