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


C# UnaryOpStorage类代码示例

本文整理汇总了C#中UnaryOpStorage的典型用法代码示例。如果您正苦于以下问题:C# UnaryOpStorage类的具体用法?C# UnaryOpStorage怎么用?C# UnaryOpStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ToString

        public override string ToString() {
#if DEBUG // This can be made un-conditional after RubyTypeBuilder is also updated to override ToString
            UnaryOpStorage unaryOpStorage = new UnaryOpStorage(_class.Context);
            return RubyUtils.ObjectToMutableString(unaryOpStorage, this).ConvertToString();
#else
            return base.ToString();
#endif
        }
开发者ID:toddb,项目名称:ironruby,代码行数:8,代码来源:RubyObject.cs

示例2: Abs

 public static object Abs(BinaryOpStorage/*!*/ lessThanStorage, UnaryOpStorage/*!*/ minusStorage, object self)
 {
     var lessThan = lessThanStorage.GetCallSite("<");
     if (RubyOps.IsTrue(lessThan.Target(lessThan, self, 0))) {
         var minus = minusStorage.GetCallSite("[email protected]");
         return minus.Target(minus, self);
     }
     return self;
 }
开发者ID:TerabyteX,项目名称:main,代码行数:9,代码来源:Numeric.cs

示例3: Compact

        public static IList Compact(UnaryOpStorage/*!*/ allocateStorage, IList/*!*/ self)
        {
            IList result = CreateResultArray(allocateStorage, self);

            foreach (object item in self) {
                if (item != null) {
                    result.Add(item);
                }
            }

            allocateStorage.Context.TaintObjectBy(result, self);

            return result;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:14,代码来源:IListOps.cs

示例4: Union

        public static RubyArray/*!*/ Union(UnaryOpStorage/*!*/ hashStorage, BinaryOpStorage/*!*/ eqlStorage, 
            IList/*!*/ self, [DefaultProtocol]IList other) {
            var seen = new Dictionary<object, bool>(new EqualityComparer(hashStorage, eqlStorage));
            bool nilSeen = false;
            var result = new RubyArray();

            // Union merges the two arrays, removing duplicates
            AddUniqueItems(self, result, seen, ref nilSeen);

            AddUniqueItems(other, result, seen, ref nilSeen);

            return result;
        }
开发者ID:aceptra,项目名称:ironruby,代码行数:13,代码来源:IListOps.cs

示例5: GetHashCode

 public static int GetHashCode(UnaryOpStorage/*!*/ hashStorage, ConversionStorage<int>/*!*/ fixnumCast, IList/*!*/ self) {
     return RubyArray.GetHashCode(hashStorage, fixnumCast, self);
 }
开发者ID:aceptra,项目名称:ironruby,代码行数:3,代码来源:IListOps.cs

示例6: UniqueSelf

        public static IList UniqueSelf(UnaryOpStorage/*!*/ hashStorage, BinaryOpStorage/*!*/ eqlStorage, IList/*!*/ self) {
            var seen = new Dictionary<object, bool>(new EqualityComparer(hashStorage, eqlStorage));
            bool nilSeen = false;
            bool modified = false;
            int i = 0;
            while (i < self.Count) {
                object key = self[i];
                if (key != null && !seen.ContainsKey(key)) {
                    seen.Add(key, true);
                    i++;
                } else if (key == null && !nilSeen) {
                    nilSeen = true;
                    i++;
                } else {
                    self.RemoveAt(i);
                    modified = true;
                }
            }

            return modified ? self : null;
        }
开发者ID:aceptra,项目名称:ironruby,代码行数:21,代码来源:IListOps.cs

示例7: IsNonZero

 public static object IsNonZero(UnaryOpStorage/*!*/ isZeroStorage, RubyContext/*!*/ context, object self) {
     var isZero = isZeroStorage.GetCallSite("zero?");
     return Protocols.IsTrue(isZero.Target(isZero, context, self)) ? null : self;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:4,代码来源:Numeric.cs

示例8: ToYaml

        public static Node/*!*/ ToYaml(UnaryOpStorage/*!*/ beginStorage, UnaryOpStorage/*!*/ endStorage, UnaryOpStorage/*!*/ exclStorage, 
            Range/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) {

            var begin = beginStorage.GetCallSite("begin");
            var end = endStorage.GetCallSite("end");

            var map = new Dictionary<MutableString, object>() {
                { MutableString.Create("begin"), begin.Target(begin, rep.Context, self) },
                { MutableString.Create("end"), end.Target(end, rep.Context, self) },
                { MutableString.Create("excl"), self.ExcludeEnd },
            };

            rep.AddYamlProperties(self, map);
            return rep.Map(self, map);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:15,代码来源:BuiltinsOps.cs

示例9: IsBinaryData

        public static object IsBinaryData(UnaryOpStorage/*!*/ isEmptyStorage, RubyContext/*!*/ context, MutableString/*!*/ self) {

            var site = isEmptyStorage.GetCallSite("empty?");
            if (RubyOps.IsTrue(site.Target(site, context, self))) {
                return null;
            }

            return ScriptingRuntimeHelpers.BooleanToObject((self.IsBinary ? self.IndexOf(0) : self.IndexOf('\0')) >= 0);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:BuiltinsOps.cs

示例10: StepString

        /// <summary>
        /// Step through a Range of Strings.
        /// </summary>
        /// <remarks>
        /// This method requires step to be a Fixnum.
        /// It uses a hybrid string comparison to prevent infinite loops and calls String#succ to get each item in the range.
        /// </remarks>
        private static object StepString(
            ConversionStorage<MutableString>/*!*/ stringCast, 
            BinaryOpStorage/*!*/ comparisonStorage,
            BinaryOpStorage/*!*/ lessThanStorage,
            BinaryOpStorage/*!*/ greaterThanStorage,
            UnaryOpStorage/*!*/ succStorage, 
            BlockParam block, Range/*!*/ self, MutableString begin, MutableString end, int step) {

            CheckStep(step);
            object result;
            MutableString item = begin;
            int comp;

            var succSite = succStorage.GetCallSite("succ");
            while ((comp = Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, item, end)) < 0) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                if (block.Yield(item, out result)) {
                    return result;
                }

                for (int i = 0; i < step; i++) {
                    item = Protocols.CastToString(stringCast, succSite.Target(succSite, item));
                }

                if (item.Length > end.Length) {
                    return self;
                }
            }

            if (comp == 0 && !self.ExcludeEnd) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                } 
                
                if (block.Yield(item, out result)) {
                    return result;
                }
            }
            return self;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:50,代码来源:RangeOps.cs

示例11: Step

        public static object Step(
            ConversionStorage<MutableString>/*!*/ stringCast, 
            ConversionStorage<int>/*!*/ fixnumCast, 
            RespondToStorage/*!*/ respondToStorage,
            BinaryOpStorage/*!*/ comparisonStorage,
            BinaryOpStorage/*!*/ lessThanStorage,
            BinaryOpStorage/*!*/ lessThanEqualsStorage,
            BinaryOpStorage/*!*/ greaterThanStorage,
            BinaryOpStorage/*!*/ equalsStorage,
            BinaryOpStorage/*!*/ addStorage,
            UnaryOpStorage/*!*/ succStorage,
            BlockParam block, Range/*!*/ self, [Optional]object step) {

            if (step == Missing.Value) {
                step = ClrInteger.One;
            }

            // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
            // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
            if (self.Begin is int && self.End is int) {
                // self.begin is Fixnum; directly call item = item + 1 instead of succ
                int intStep = Protocols.CastToFixnum(fixnumCast, step);
                return StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep);
            } else if (self.Begin is MutableString ) {
                // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
                int intStep = Protocols.CastToFixnum(fixnumCast, step);
                return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage, 
                    block, self, (MutableString)self.Begin, (MutableString)self.End, intStep
                );
            } else if (succStorage.Context.IsInstanceOf(self.Begin, succStorage.Context.GetClass(typeof(Numeric)))) {
                // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
                return StepNumeric(lessThanStorage, lessThanEqualsStorage, equalsStorage, addStorage,  
                    block, self, self.Begin, self.End, step
                );
            } else {
                // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
                CheckBegin(respondToStorage, self.Begin);
                int intStep = Protocols.CastToFixnum(fixnumCast, step);
                return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage, 
                    block, self, self.Begin, self.End, intStep
                );
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:43,代码来源:RangeOps.cs

示例12: Each

        public static object Each(
            ConversionStorage<MutableString>/*!*/ stringCast, 
            RespondToStorage/*!*/ respondToStorage,
            BinaryOpStorage/*!*/ comparisonStorage,
            BinaryOpStorage/*!*/ lessThanStorage,
            BinaryOpStorage/*!*/ greaterThanStorage,
            BinaryOpStorage/*!*/ equalsStorage,
            UnaryOpStorage/*!*/ succStorage,
            BlockParam block, Range/*!*/ self) {

            // We check that self.begin responds to "succ" even though some of the implementations don't use it.
            CheckBegin(respondToStorage, self.Begin);

            if (self.Begin is int && self.End is int) {
                return StepFixnum(block, self, (int)self.Begin, (int)self.End, 1);
            } else if (self.Begin is MutableString) {
                return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage,  
                    block, self, (MutableString)self.Begin, (MutableString)self.End, 1
                );
            } else {
                return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage,  
                    block, self, self.Begin, self.End, 1
                );
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:25,代码来源:RangeOps.cs

示例13: GetHashCode

 public static int GetHashCode(UnaryOpStorage/*!*/ hashStorage, Range/*!*/ self) {
     // MRI: Ruby treatment of hash return value is inconsistent. 
     // No conversions happen here (unlike e.g. Array.hash).
     var hashSite = hashStorage.GetCallSite("hash");
     return unchecked(
         Protocols.ToHashCode(hashSite.Target(hashSite, self.Begin)) ^
         Protocols.ToHashCode(hashSite.Target(hashSite, self.End)) ^ 
         (self.ExcludeEnd ? 179425693 : 1794210891)
     );
 }
开发者ID:Jirapong,项目名称:main,代码行数:10,代码来源:RangeOps.cs

示例14: RejectImpl

        private static object RejectImpl(CallSiteStorage<EachSite>/*!*/ each, UnaryOpStorage/*!*/ allocate, 
            BlockParam/*!*/ predicate, IList/*!*/ self) {

            IList result = CreateResultArray(allocate, self);

            for (int i = 0; i < self.Count; i++) {
                object item = self[i];
                object blockResult;
                if (predicate.Yield(item, out blockResult)) {
                    return blockResult;
                }

                if (RubyOps.IsFalse(blockResult)) {
                    result.Add(item);
                }
            }

            return result;
        }
开发者ID:jschementi,项目名称:iron,代码行数:19,代码来源:IListOps.cs

示例15: Reject

 public static object Reject(CallSiteStorage<EachSite>/*!*/ each, UnaryOpStorage/*!*/ allocate,
     BlockParam predicate, IList/*!*/ self) {
     return (predicate != null) ? RejectImpl(each, allocate, predicate, self) : new Enumerator((_, block) => RejectImpl(each, allocate, block, self));
 }
开发者ID:jschementi,项目名称:iron,代码行数:4,代码来源:IListOps.cs


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