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


C# IParameters.Any方法代码示例

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


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

示例1: ValueOperation

        public ValueOperation(string outKey, string outType, string value, IParameters parameters)
            : base(string.Empty, outKey) {
            _parameters = parameters;
            if (!value.Equals(string.Empty)) {
                _value = Common.GetObjectConversionMap()[Common.ToSimpleType(outType)](value);
            } else if (!_parameters.Any()) {
                throw new TransformalizeException(Logger, EntityName, "The value transform method requires the value attribute to be set, or a parameter.");
            }

            Name = string.Format("ValueOperation ({0})", outKey);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:11,代码来源:ValueOperation.cs

示例2: JavascriptOperation

        public JavascriptOperation(
            string outKey, 
            string script, 
            Dictionary<string, Script> scripts, 
            IParameters parameters,
            ILogger logger)
            : base(string.Empty, outKey) {
            _script = script;
            _parameters = parameters;
            _addSelf = !parameters.Any();

            foreach (var pair in scripts) {
                logger.Debug("Running script {0}.", pair.Value.File);
                try
                {
                    var program = new JavaScriptParser().Parse(pair.Value.Content, new ParserOptions { Tolerant = true});
                    if (program.Errors != null && program.Errors.Count > 0) {
                        logger.Warn("Javascript Parse Failed. Script: {0}.", pair.Value.Name);
                        foreach (var error in program.Errors) {
                            logger.Warn(error.Description);
                        }
                    } else {
                        _scriptAppender.AppendLine(pair.Value.Content);
                    }
                }
                catch (Exception e) {
                    logger.Error("Javascript Parse Failed. Name: {0}. Script: {1}.", pair.Value.Name, pair.Value.Content);
                    logger.Error(e.Message);
                }
            }

            var externalScripts = _scriptAppender.ToString();
            if (externalScripts.Equals(string.Empty))
                return;

            logger.Debug("Loading scripts into Javascript engine...");
            logger.Debug(externalScripts.Replace("{","{{").Replace("}","}}"));
            _jint.Execute(externalScripts);

            Name = string.Format("Javascript({0}=>{1})", InKey, OutKey);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:41,代码来源:JavascriptOperation.cs

示例3: CSharpOperation

        public CSharpOperation(string outKey, string outType, string script, Dictionary<string, Script> scripts, IParameters parameters)
            : base(string.Empty, outKey) {

            var csc = new CSharpCodeProvider();
            var ca = Assembly.GetExecutingAssembly();
            var cp = new CompilerParameters { GenerateInMemory = true };
            var testRow = new Row();

            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Core.dll");
            cp.ReferencedAssemblies.Add("mscorlib.dll");
            cp.ReferencedAssemblies.Add(ca.Location);

            var scriptBuilder = new StringBuilder(string.Empty);
            foreach (var s in scripts) {
                scriptBuilder.AppendLine($"// {s.Value.Name} script");
                scriptBuilder.AppendLine(s.Value.Content);
            }

            var castBuilder = new StringBuilder(string.Empty);

            if (!parameters.Any()) {
                castBuilder.AppendLine(string.Format("{1} {0} = ({1}) row[\"{0}\"];", OutKey, Common.ToSystemType(outType)));
                testRow[OutKey] = new DefaultFactory(Logger).Convert(null, outType);
            } else {
                var map = Common.GetLiteral();
                foreach (var pair in parameters) {
                    if (pair.Value.HasValue()) {
                        castBuilder.AppendLine($"{Common.ToSystemType(pair.Value.SimpleType)} {pair.Value.Name} = {map[pair.Value.SimpleType](pair.Value.Value)};");
                    } else {
                        castBuilder.AppendLine(string.Format("{1} {0} = ({1}) row[\"{0}\"];", pair.Value.Name, Common.ToSystemType(pair.Value.SimpleType)));
                    }
                    testRow[pair.Value.Name] = new DefaultFactory(Logger).Convert(null, pair.Value.SimpleType);
                }
            }

            var code = [email protected]"using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Transformalize.Operations.Transform;
using Transformalize.Libs.Rhino.Etl;

{scriptBuilder}

public class Transformer : ITransformer
{{
    public object Transform(Row row)
    {{
        {castBuilder}
        //User's script
        {script}
    }}
}}";

            Logger.EntityDebug(EntityName, "Compiling this code:");
            Logger.EntityDebug(EntityName, code);

            var res = csc.CompileAssemblyFromSource(
                cp,
                code
            );

            if (res.Errors.Count == 0) {
                var type = res.CompiledAssembly.GetType("Transformer");
                _transformer = (ITransformer)Activator.CreateInstance(type);
                try {
                    var test = _transformer.Transform(testRow);
                    Logger.EntityDebug(EntityName, "CSharp transform compiled and passed test. {0}", test);
                } catch (Exception e) {
                    Logger.EntityDebug(EntityName, "CSharp transform compiled but failed test. {0}", e.Message);
                    Logger.EntityDebug(EntityName, e.StackTrace);
                }
            } else {
                foreach (var error in res.Errors) {
                    Logger.EntityError(EntityName, error.ToString());
                }
                throw new TransformalizeException(Logger, EntityName, "Failed to compile code. {0}", code);
            }

            Name = $"CSharpOperation ({outKey})";
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:82,代码来源:CSharpOperation.cs


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