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


C# Machine.Evaluate方法代码示例

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


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

示例1: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            object name = arguments[0];

            object result = machine.Evaluate(name, environment);

            Type type = null;

            if (!(result is Type))
            {
                if (name is INamed || name is string)
                    type = Utilities.GetType(name);

                if (type == null)
                    throw new ArgumentException("New should receive a type name");
            }
            else
                type = (Type)result;

            object[] parameters = new object[arguments.Length - 1];

            for (int k = 1; k < arguments.Length; k++)
                parameters[k - 1] = machine.Evaluate(arguments[k], environment);

            return Activator.CreateInstance(type, parameters);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:26,代码来源:NewPrimitive.cs

示例2: ApplyToObject

        public object ApplyToObject(object obj, Machine machine, ValueEnvironment environment, object[] arguments)
        {
            Type type = obj.GetType();
            INamed named = null;
            object[] pars = null;

            if (arguments[1] is IList)
            {
                IList parameters = (IList)arguments[1];
                named = (INamed)parameters[0];
                pars = new object[parameters.Count - 1];
                for (int k = 1; k < parameters.Count; k++)
                    pars[k - 1] = machine.Evaluate(parameters[k], environment);
            }
            else
            {
                named = (INamed)arguments[1];
                pars = new object[arguments.Length - 2];

                for (int k = 2; k < arguments.Length; k++)
                    pars[k - 2] = machine.Evaluate(arguments[k], environment);
            }

            return type.InvokeMember(named.Name, System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Instance, null, obj, pars);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:25,代码来源:DotPrimitive.cs

示例3: Evaluate

        public object Evaluate(Machine machine, ValueEnvironment environment)
        {
            // TODO get a predefined empty dictionary object
            IPersistentMap map = new DictionaryObject(new Hashtable());

            foreach (DictionaryEntry entry in this.map)
            {
                object key = machine.Evaluate(entry.Key, environment);
                object value = machine.Evaluate(entry.Value, environment);

                map = map.Associate(key, value);
            }

            return map;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:15,代码来源:MapExpression.cs

示例4: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            object result = null;
            ValueEnvironment newenv = null;

            foreach (object argument in arguments)
            {
                if (newenv == null)
                {
                    newenv = new ValueEnvironment(environment);

                    if (argument != null)
                    {
                        if (!(argument is ICollection))
                            throw new InvalidOperationException("Let must receive a list as first argument");

                        Utilities.EvaluateBindings(machine, newenv, (ICollection)argument);
                    }
                }
                else
                    result = machine.Evaluate(argument, newenv);
            }

            return result;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:25,代码来源:LetPrimitive.cs

示例5: Evaluate

        public object Evaluate(Machine machine, ValueEnvironment environment)
        {
            if (this.elements == null || this.elements.Count == 0)
                return null;

            IExpression formhead = (IExpression)Utilities.ToExpression(this.elements[0]);

            IFunction function = (IFunction)formhead.Evaluate(machine, environment);

            if (function == null)
            {
                if (this.elements[0] is INamed)
                    throw new InvalidOperationException(string.Format("Unknown form {0}", ((INamed)this.elements[0]).FullName));
                else
                    throw new InvalidOperationException(string.Format("Unknown form {0}", this.elements[0].ToString()));
            }

            object[] arguments = null;

            if (this.elements.Count > 1)
                arguments = new object[this.elements.Count - 1];

            if (function.IsSpecialForm)
                for (int k = 1; k < this.elements.Count; k++)
                    arguments[k - 1] = this.elements[k];
            else
                for (int k = 1; k < this.elements.Count; k++)
                    arguments[k - 1] = machine.Evaluate(this.elements[k], environment);

            return function.Apply(machine, environment, arguments);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:31,代码来源:ListExpression.cs

示例6: Evaluate

        public object Evaluate(Machine machine, ValueEnvironment environment)
        {
            IDictionary result = new Hashtable();

            foreach (object key in this.dictionary.Keys)
            {
                object value = this.dictionary[key];

                object newkey = machine.Evaluate(key, environment);

                object newvalue = machine.Evaluate(value, environment);

                result[newkey] = newvalue;
            }

            return result;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:17,代码来源:DictionaryExpression.cs

示例7: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            object result = null;

            foreach (object argument in arguments)
                result = machine.Evaluate(argument, environment);

            return result;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:9,代码来源:DoPrimitive.cs

示例8: Evaluate

        public object Evaluate(Machine machine, ValueEnvironment environment)
        {
            object[] result = new object[this.vector.Count];

            for (int k = 0; k < this.vector.Length; k++)
                result[k] = machine.Evaluate(this.vector[k], environment);

            return PersistentVector.Create(result);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:9,代码来源:VectorExpression.cs

示例9: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length < 2)
                throw new InvalidOperationException("If should receive a test and a body");
            if (arguments.Length > 3)
                throw new InvalidOperationException("Too many arguments to If");

            object result = machine.Evaluate(arguments[0], environment);

            if (Utilities.IsFalse(result))
            {
                if (arguments.Length == 3)
                    return machine.Evaluate(arguments[2], environment);
                return null;
            }
            else
                return machine.Evaluate(arguments[1], environment);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:18,代码来源:IfPrimitive.cs

示例10: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length == 0)
                return null;

            object result = null;
            ValueEnvironment newenv = null;
            string[] names = null;

            newenv = new ValueEnvironment(environment);

            object argument = arguments[0];

            if (argument != null)
            {
                if (!(argument is ICollection))
                    throw new InvalidOperationException("Let must receive a list as first argument");

                names = Utilities.EvaluateBindings(machine, newenv, (ICollection)argument);
            }

            for (int k = 1; k < arguments.Length; k++)
                result = machine.Evaluate(arguments[k], newenv);

            while (result != null && result is RecursionData)
            {
                RecursionData data = (RecursionData)result;

                if (Utilities.GetArity(data.Arguments) != Utilities.GetArity(names))
                    throw new InvalidOperationException("Invalid recursion data");

                newenv = new ValueEnvironment(environment);
                result = null;

                for (int k = 0; k < names.Length; k++)
                    newenv.SetValue(names[k], data.Arguments[k]);

                for (int k = 1; k < arguments.Length; k++)
                    result = machine.Evaluate(arguments[k], newenv);
            }

            return result;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:43,代码来源:LoopPrimitive.cs

示例11: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            Symbol symbol = (Symbol)arguments[0];

            if (!string.IsNullOrEmpty(symbol.Namespace))
                throw new InvalidOperationException("Defined name should not have namespace");

            Variable variable = Utilities.ToVariable(machine, environment, symbol);

            object value = machine.Evaluate(arguments[1], environment);

            if (symbol.Metadata != null)
            {
                IDictionary dictionary = (IDictionary)symbol.Metadata;
                IDictionary evaluated = new Hashtable();

                foreach (object key in dictionary.Keys)
                {
                    object val = machine.Evaluate(dictionary[key], environment);
                    evaluated[key] = val;
                }

                variable.ResetMetadata(new DictionaryObject(evaluated));
            }
            else
                variable.ResetMetadata(null);

            IPersistentMap metadata = variable.Metadata;

            if (metadata != null && metadata.ContainsKey(macroKeyword))
                if ((bool)metadata.ValueAt(macroKeyword) && value is DefinedFunction)
                    value = ((DefinedFunction)value).ToMacro();

            machine.SetVariableValue(variable, value);

            if (value is IFunction && ((IFunction)value).IsSpecialForm)
                machine.Environment.SetValue(variable.Name, value, true);

            return value;
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:40,代码来源:DefPrimitive.cs

示例12: Apply

        public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
        {
            object name = arguments[0];

            object result = machine.Evaluate(name, environment);

            Type type = null;

            if (name is INamed || name is string)
                type = Utilities.GetType(name);

            if (type != null)
                return this.ApplyToType(type, machine, environment, arguments);

            return this.ApplyToObject(result, machine, environment, arguments);
        }
开发者ID:ajlopez,项目名称:AjSharpure,代码行数:16,代码来源:DotPrimitive.cs


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