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


C# Permutation.IsNullOrEmpty方法代码示例

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


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

示例1: GetIndex

        private int GetIndex(string innerMacro, Permutation eachItems) {
            if (eachItems.IsNullOrEmpty()) {
                return -1;
            }

            for (int i = 0; i < eachItems.Names.Length; i++) {
                if (eachItems.Names[i] == innerMacro) {
                    return i;
                }
            }

            int ndx;
            if (!Int32.TryParse(innerMacro, out ndx)) {
                return innerMacro.Equals("each", StringComparison.CurrentCultureIgnoreCase) ? 0 : -1;
            }
            return ndx;
        }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:17,代码来源:View.cs

示例2: ResolveMacrosInContext

        public string ResolveMacrosInContext(string value, Permutation eachItems = null, bool itemsOnly = false) {
            bool keepGoing;

            if(string.IsNullOrEmpty(value)) {
                return value;
            }

            do {
                keepGoing = false;

                var matches = _macro.Matches(value);
                foreach(var m in matches) {
                    var match = m as Match;
                    var innerMacro = match.Groups[2].Value;
                    var outerMacro = match.Groups[1].Value;

                    string replacement = null;

                    var ndx = GetIndex(innerMacro, eachItems);
                    if(!itemsOnly && ndx < 0) {
                        // get the first responder.
                        var indexOfDot = innerMacro.IndexOf('.');

                        if(indexOfDot > -1) {
                            var membr = innerMacro.Substring(0, indexOfDot);
                            var val = LookupMacroValue(membr, this);
                            if(val != null) {
                                var obval = val.SimpleEval2(innerMacro.Substring(indexOfDot + 1).Trim());
                                if(obval != null) {
                                    replacement = obval.ToString();
                                }
                            }
                        }
                        else {
                            var mv = LookupMacroValue(innerMacro, this);
                            if (!mv.IsNullOrEmpty()) {
                                replacement = mv.CollapseToString();
                            }
                            // replacement = LookupMacroValue(innerMacro, this).CollapseToString();
                        }
                    }

                    if(!eachItems.IsNullOrEmpty()) {
                        // hardcoded to produce permutation string map.
                        if (innerMacro.Equals("Permutation", StringComparison.CurrentCultureIgnoreCase)) {
                            replacement = eachItems.Names.Zip(eachItems.Values, (a, b) => "{0}={1}".format(a, b.ToString())).Aggregate((each, current) => each + ";" + current);
                        }

                        // try resolving it as an ${each.property} style.
                        // the element at the front is the 'this' value
                        // just trim off whatever is at the front up to and including the first dot.
                        try {
                            if(ndx >= 0) {
                                if(ndx < eachItems.Values.Length) {
                                    value = value.Replace(outerMacro, eachItems.Values[ndx].ToString());
                                    keepGoing = true;
                                }
                            }
                            else {
                                if(innerMacro.Contains(".")) {
                                    var indexOfDot = innerMacro.IndexOf('.');
                                    ndx = GetIndex(innerMacro.Substring(0, indexOfDot), eachItems);
                                    if(ndx >= 0) {
                                        if(ndx < eachItems.Values.Length) {
                                            innerMacro = innerMacro.Substring(indexOfDot + 1).Trim();

                                            var v = eachItems.Values[ndx].SimpleEval2(innerMacro);
                                            if(v != null) {
                                                var r = v.ToString();
                                                value = value.Replace(outerMacro, r);
                                                keepGoing = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch {
                            // meh. screw em'
                        }
                    }

                    if(replacement != null) {
                        value = value.Replace(outerMacro, replacement);
                        keepGoing = true;
                        break;
                    }
                }
            } while(keepGoing);
            return value.Replace("${ElementId}", "").Replace("${conditionFolder}", "");
        }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:91,代码来源:View.cs


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