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


C# ConversionStorage.GetSite方法代码示例

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


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

示例1: CreateArray

        public static object CreateArray(ConversionStorage<Union<IList, int>>/*!*/ toAryToInt,
            BlockParam block, RubyClass/*!*/ self, [NotNull]object/*!*/ arrayOrSize) {

            var site = toAryToInt.GetSite(CompositeConversionAction.Make(toAryToInt.Context, CompositeConversion.ToAryToInt));
            var union = site.Target(site, arrayOrSize);

            if (union.First != null) {
                // block ignored
                return CreateArray(union.First);
            } else if (block != null) {
                return CreateArray(block, union.Second);
            } else {
                return CreateArray(self, union.Second, null);
            }
        }
开发者ID:toddb,项目名称:ironruby,代码行数:15,代码来源:ArrayOps.cs

示例2: Reinitialize

        public static RubyFile/*!*/ Reinitialize(
            ConversionStorage<int?>/*!*/ toInt,
            ConversionStorage<IDictionary<object, object>>/*!*/ toHash,
            ConversionStorage<MutableString>/*!*/ toPath,
            ConversionStorage<MutableString>/*!*/ toStr,
            RubyFile/*!*/ self,
            object descriptorOrPath, 
            [Optional]object optionsOrMode, 
            [Optional]object optionsOrPermissions,
            [DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) {

            var context = self.Context;
            
            Protocols.TryConvertToOptions(toHash, ref options, ref optionsOrMode, ref optionsOrPermissions);
            var toIntSite = toInt.GetSite(TryConvertToFixnumAction.Make(toInt.Context));

            IOInfo info = new IOInfo();
            if (optionsOrMode != Missing.Value) {
                int? m = toIntSite.Target(toIntSite, optionsOrMode);
                info = m.HasValue ? new IOInfo((IOMode)m) : IOInfo.Parse(context, Protocols.CastToString(toStr, optionsOrMode));
            }

            int permissions = 0;
            if (optionsOrPermissions != Missing.Value) {
                int? p = toIntSite.Target(toIntSite, optionsOrPermissions);
                if (!p.HasValue) {
                    throw RubyExceptions.CreateTypeConversionError(context.GetClassName(optionsOrPermissions), "Integer");
                }
                permissions = p.Value;
            }

            if (options != null) {
                info = info.AddOptions(toStr, options);
            }

            // TODO: permissions
            
            // descriptor or path:
            int? descriptor = toIntSite.Target(toIntSite, descriptorOrPath);
            if (descriptor.HasValue) {
                RubyIOOps.Reinitialize(self, descriptor.Value, info);
            } else {
                Reinitialize(self, Protocols.CastToPath(toPath, descriptorOrPath), info, permissions);
            }

            return self;
        }
开发者ID:rpattabi,项目名称:ironruby,代码行数:47,代码来源:FileOps.cs

示例3: CreateSubclass

        public static Hash/*!*/ CreateSubclass(ConversionStorage<IDictionary<object, object>>/*!*/ toHash, ConversionStorage<IList>/*!*/ toAry,
            RubyClass/*!*/ self, object listOrHash) {

            var toHashSite = toHash.GetSite(TryConvertToHashAction.Make(toHash.Context));
            var hash = toHashSite.Target(toHashSite, listOrHash);
            if (hash != null) {
                return CreateSubclass(self, hash);
            }

            var toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context));
            var array = toArySite.Target(toArySite, listOrHash);
            if (array != null) {
                return CreateSubclass(toAry, self, array);
            }

            throw RubyExceptions.CreateArgumentError("odd number of arguments for Hash");
        }
开发者ID:jschementi,项目名称:iron,代码行数:17,代码来源:HashOps.cs

示例4: Reinitialize

        public static object Reinitialize(ConversionStorage<Union<IList, int>>/*!*/ toAryToInt,
            BlockParam block, RubyArray/*!*/ self, [NotNull]object/*!*/ arrayOrSize) {

            var context = toAryToInt.Context;

            var site = toAryToInt.GetSite(CompositeConversionAction.Make(context, CompositeConversion.ToAryToInt));
            var union = site.Target(site, arrayOrSize);
            
            if (union.First != null) {
                // block ignored
                return Reinitialize(self, union.First);
            } else if (block != null) {
                return Reinitialize(block, self, union.Second);
            } else {
                return ReinitializeByRepeatedValue(context, self, union.Second, null);
            }
        }
开发者ID:Jirapong,项目名称:main,代码行数:17,代码来源:ArrayOps.cs

示例5: Read

        public static MutableString/*!*/ Read(ConversionStorage<int>/*!*/ fixnumCast, RubyClass/*!*/ self,
            [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultParameterValue(null)]object lengthObj, 
            [DefaultParameterValue(0)]object offsetObj) {

            var site = fixnumCast.GetSite(ConvertToFixnumAction.Make(fixnumCast.Context));
            int length = (lengthObj != null) ? site.Target(site, lengthObj) : 0;
            int offset = (offsetObj != null) ? site.Target(site, offsetObj) : 0;

            if (offset < 0) {
                throw RubyExceptions.CreateEINVAL();
            }

            if (length < 0) {
                throw RubyExceptions.CreateArgumentError("negative length {0} given", length);
            }

            using (RubyIO io = new RubyFile(self.Context, path.ConvertToString(), IOMode.ReadOnly)) {
                if (offset > 0) {
                    io.Seek(offset, SeekOrigin.Begin);
                }

                if (lengthObj == null) {
                    return Read(io);
                } else {
                    return Read(io, length, null);
                }
            }
        }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:28,代码来源:IoOps.cs

示例6: CastToFixnum

 public static int CastToFixnum(ConversionStorage<int>/*!*/ conversionStorage, RubyContext/*!*/ context, object value) {
     var site = conversionStorage.GetSite(ConvertToFixnumAction.Instance);
     return site.Target(site, context, value);
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:4,代码来源:Protocols.cs

示例7: CopyStream

        public static object CopyStream(
            ConversionStorage<MutableString>/*!*/ toPath, ConversionStorage<int>/*!*/ toInt, RespondToStorage/*!*/ respondTo,
            BinaryOpStorage/*!*/ writeStorage, CallSiteStorage<Func<CallSite, object, object, object, object>>/*!*/ readStorage,
            RubyClass/*!*/ self, object src, object dst, [DefaultParameterValue(-1)]int count, [DefaultParameterValue(-1)]int src_offset) {

            if (count < -1) {
                throw RubyExceptions.CreateArgumentError("count should be >= -1");
            }

            if (src_offset < -1) {
                throw RubyExceptions.CreateArgumentError("src_offset should be >= -1");
            }

            RubyIO srcIO = src as RubyIO;
            RubyIO dstIO = dst as RubyIO;
            Stream srcStream = null, dstStream = null;
            var context = toPath.Context;
            CallSite<Func<CallSite, object, object, object>> writeSite = null;
            CallSite<Func<CallSite, object, object, object, object>> readSite = null;

            try {
                if (srcIO == null || dstIO == null) {
                    var toPathSite = toPath.GetSite(TryConvertToPathAction.Make(toPath.Context));
                    var srcPath = toPathSite.Target(toPathSite, src);
                    if (srcPath != null) {
                        srcStream = new FileStream(context.DecodePath(srcPath), FileMode.Open, FileAccess.Read);
                    } else {
                        readSite = readStorage.GetCallSite("read", 2);
                    }

                    var dstPath = toPathSite.Target(toPathSite, dst);
                    if (dstPath != null) {
                        dstStream = new FileStream(context.DecodePath(dstPath), FileMode.Truncate);
                    } else {
                        writeSite = writeStorage.GetCallSite("write", 1);
                    }
                } else {
                    srcStream = srcIO.GetReadableStream();
                    dstStream = dstIO.GetWritableStream();
                }

                if (src_offset != -1) {
                    if (srcStream == null) {
                        throw RubyExceptions.CreateArgumentError("cannot specify src_offset for non-IO");
                    }
                    srcStream.Seek(src_offset, SeekOrigin.Current);
                }

                MutableString userBuffer = null;
                byte[] buffer = null;

                long bytesCopied = 0;
                long remaining = (count < 0) ? Int64.MaxValue : count;
                int minBufferSize = 16 * 1024;
                
                if (srcStream != null) {
                    buffer = new byte[Math.Min(minBufferSize, remaining)];
                }

                while (remaining > 0) {
                    int bytesRead;
                    int chunkSize = (int)Math.Min(minBufferSize, remaining);
                    if (srcStream != null) {
                        userBuffer = null;
                        bytesRead = srcStream.Read(buffer, 0, chunkSize);
                    } else {
                        userBuffer = MutableString.CreateBinary();
                        bytesRead = Protocols.CastToFixnum(toInt, readSite.Target(readSite, src, chunkSize, userBuffer));
                    }
                    
                    if (bytesRead <= 0) {
                        break;
                    }

                    if (dstStream != null) {
                        if (userBuffer != null) {
                            dstStream.Write(userBuffer, 0, bytesRead);
                        } else {
                            dstStream.Write(buffer, 0, bytesRead);
                        }
                    } else {
                        if (userBuffer == null) {
                            userBuffer = MutableString.CreateBinary(bytesRead).Append(buffer, 0, bytesRead);
                        } else {
                            userBuffer.SetByteCount(bytesRead);
                        }
                        writeSite.Target(writeSite, dst, userBuffer);
                    }
                    bytesCopied += bytesRead;
                    remaining -= bytesRead;
                }
                return Protocols.Normalize(bytesCopied);

            } finally {
                if (srcStream != null) {
                    srcStream.Close();
                }
                if (dstStream != null) {
                    dstStream.Close();
                }
//.........这里部分代码省略.........
开发者ID:ghouston,项目名称:ironlanguages,代码行数:101,代码来源:IoOps.cs

示例8: CastToFixnum

 public static int CastToFixnum(ConversionStorage<int>/*!*/ conversionStorage, object value) {
     var site = conversionStorage.GetSite(ConvertToFixnumAction.Make(conversionStorage.Context));
     return site.Target(site, value);
 }
开发者ID:nieve,项目名称:ironruby,代码行数:4,代码来源:Protocols.cs

示例9: CastToInteger

 public static IntegerValue CastToInteger(ConversionStorage<IntegerValue>/*!*/ integerConversion, object value) {
     var site = integerConversion.GetSite(ConvertToIntAction.Make(integerConversion.Context));
     return site.Target(site, value);
 }
开发者ID:nieve,项目名称:ironruby,代码行数:4,代码来源:Protocols.cs

示例10: TryCastToArray

 public static IList TryCastToArray(ConversionStorage<IList>/*!*/ arrayTryCast, object obj) {
     var site = arrayTryCast.GetSite(TryConvertToArrayAction.Make(arrayTryCast.Context));
     return site.Target(site, obj);
 }
开发者ID:nieve,项目名称:ironruby,代码行数:4,代码来源:Protocols.cs

示例11: TryCastToString

 /// <summary>
 /// Converts an object to string using try-to_str protocol (<see cref="TryConvertToStrAction"/>).
 /// </summary>
 public static MutableString TryCastToString(ConversionStorage<MutableString>/*!*/ stringTryCast, object obj) {
     var site = stringTryCast.GetSite(TryConvertToStrAction.Make(stringTryCast.Context));
     return site.Target(site, obj);
 }
开发者ID:nieve,项目名称:ironruby,代码行数:7,代码来源:Protocols.cs

示例12: Step

        public static object Step(
            BinaryOpStorage/*!*/ equals, 
            BinaryOpStorage/*!*/ greaterThanStorage,
            BinaryOpStorage/*!*/ lessThanStorage,
            BinaryOpStorage/*!*/ addStorage, 
            ConversionStorage<double>/*!*/ tofStorage,
            BlockParam block, object self, object limit, [Optional]object step) {

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

            if (self is double || limit is double || step is double) {
                var site = tofStorage.GetSite(ConvertToFAction.Make(tofStorage.Context));
                // At least one of the arguments is double so convert all to double and run the Float version of Step
                double floatSelf = self is double ? (double)self : site.Target(site, self);
                double floatLimit = limit is double ? (double)self : site.Target(site, limit);
                double floatStep = step is double ? (double)self : site.Target(site, step);
                return Step(block, floatSelf, floatLimit, floatStep);
            } else {
                #region The generic step algorithm:
                // current = self
                // if step is postive then
                //   while current < limit do
                //     yield(current)
                //     current = current + step
                //   end
                // else
                //   while current > limit do
                //     yield(current)
                //     current = current + step
                //   end
                // return self
                #endregion

                bool isStepZero = Protocols.IsEqual(equals, step, 0);
                if (isStepZero) {
                    throw RubyExceptions.CreateArgumentError("step can't be 0");
                }

                var greaterThan = greaterThanStorage.GetCallSite(">");
                bool isStepPositive = RubyOps.IsTrue(greaterThan.Target(greaterThan, step, 0));
                var compare = isStepPositive ? greaterThan : lessThanStorage.GetCallSite("<");

                object current = self;
                while (!RubyOps.IsTrue(compare.Target(compare, current, limit))) {
                    object result;
                    if (YieldStep(block, current, out result)) {
                        return result;
                    }

                    var add = addStorage.GetCallSite("+");
                    current = add.Target(add, current, step);
                }
                return self;
            }
        }
开发者ID:jschementi,项目名称:iron,代码行数:57,代码来源:Numeric.cs

示例13: Div

 public static object Div(BinaryOpStorage/*!*/ divideStorage, ConversionStorage<double>/*!*/ tofStorage, object self, object other) {
     var divide = divideStorage.GetCallSite("/");
     var tof = tofStorage.GetSite(ConvertToFAction.Make(tofStorage.Context));
     return ClrFloat.Floor(tof.Target(tof, divide.Target(divide, self, other)));
 }
开发者ID:jschementi,项目名称:iron,代码行数:5,代码来源:Numeric.cs

示例14: Coerce

        public static RubyArray/*!*/ Coerce(ConversionStorage<double>/*!*/ tof1, ConversionStorage<double>/*!*/ tof2, 
            object self, object other) {

            var context = tof1.Context;

            if (context.GetClassOf(self) == context.GetClassOf(other)) {
                return RubyOps.MakeArray2(other, self);
            }

            var site1 = tof1.GetSite(ConvertToFAction.Make(context));
            var site2 = tof2.GetSite(ConvertToFAction.Make(context));
            return RubyOps.MakeArray2(site1.Target(site1, other), site2.Target(site2, self));
        }
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:Numeric.cs

示例15: TryConvert

 public static IList TryConvert(ConversionStorage<IList>/*!*/ toAry, RubyClass/*!*/ self, object obj) {
     var site = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context));
     return site.Target(site, obj);
 }
开发者ID:Jirapong,项目名称:main,代码行数:4,代码来源:ArrayOps.cs


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