Esempio n. 1
0
 public static bool Equal(RubyContext /*!*/ context, object lhs, object rhs)
 {
     return(RubyOps.IsTrue(EqualSharedSite.Target(EqualSharedSite, context, lhs, rhs)));
 }
Esempio n. 2
0
 public static Single ConvertToSingle(object value)
 {
     return(_floatSite.Target(_floatSite, value));
 }
Esempio n. 3
0
 public static Char ConvertToChar(object value)
 {
     return(_charSite.Target(_charSite, value));
 }
Esempio n. 4
0
 public static Boolean ConvertToBoolean(object value)
 {
     return(_boolSite.Target(_boolSite, value));
 }
Esempio n. 5
0
 public static Int16 ConvertToInt16(object value)
 {
     return(_int16Site.Target(_int16Site, value));
 }
Esempio n. 6
0
 public static String ConvertToString(object value)
 {
     return(_stringSite.Target(_stringSite, value));
 }
Esempio n. 7
0
 public static Double ConvertToDouble(object value)
 {
     return(_doubleSite.Target(_doubleSite, value));
 }
Esempio n. 8
0
 public static uint ConvertToUInt32(object value)
 {
     return(_uint32Site.Target(_uint32Site, value));
 }
Esempio n. 9
0
 public static Int32 ConvertToInt32(object value)
 {
     return(_intSite.Target(_intSite, value));
 }
Esempio n. 10
0
 public static long ConvertToInt64(object value)
 {
     return(_int64Site.Target(_int64Site, value));
 }
Esempio n. 11
0
 public static ushort ConvertToUInt16(object value)
 {
     return(_uint16Site.Target(_uint16Site, value));
 }
Esempio n. 12
0
 public static double ToF(RubyContext /*!*/ context, object value)
 {
     return(_ToFSharedSite.Target(_ToFSharedSite, context, value));
 }
Esempio n. 13
0
 public static object ToInt(RubyContext /*!*/ context, object value)
 {
     return(_ToIntSharedSite.Target(_ToIntSharedSite, context, value));
 }
Esempio n. 14
0
 public static bool RespondTo(RubyContext /*!*/ context, object obj, SymbolId name)
 {
     return(RubyOps.IsTrue(RespondToSharedSite.Target(RespondToSharedSite, context, obj, name)));
 }
Esempio n. 15
0
 public static bool RespondTo(CallSite <Func <CallSite, object, object, object> > /*!*/ respondToSite, RubyContext /*!*/ context, object target, string /*!*/ methodName)
 {
     return(IsTrue(respondToSite.Target(respondToSite, target, context.EncodeIdentifier(methodName))));
 }
Esempio n. 16
0
 public static IEnumerable ConvertToIEnumerable(object o)
 {
     return(_ienumerableSite.Target(_ienumerableSite, o));
 }
Esempio n. 17
0
 private void AssignSiteDelegates(CallSite <Func <CallSite, object, int> > hashSite, CallSite <Func <CallSite, object, object, bool> > equalSite)
 {
     _hashFunc = (o) => hashSite.Target(hashSite, o);
     _eqFunc   = (o1, o2) => equalSite.Target(equalSite, o1, o2);
 }
Esempio n. 18
0
        /// <summary>
        /// Returns indication of field found, plus the value of a field for the object and name supplied.
        /// </summary>
        public static Tuple <bool, object> ExtractFieldValue(object SourceObject, string FieldName)
        {
            if (SourceObject == null)
            {
                throw new UsageAnomaly("Cannot read the member named '" + FieldName + "' from a null object reference.");
            }

            FieldInfo            FieldData = SourceObject.GetType().GetField(FieldName);
            Tuple <bool, object> Result    = null;

            /* THIS WAS NOT POSSIBLE
             * if (SourceObject is DynamicObject)
             * {
             *  var DynamicSource = SourceObject as DynamicObject;
             *  object Value = null;
             *  var MemberBinder = new GetMemberBinder();   // CANNOT BE PROVIDED. IS ABSTRACT.
             *  MemberBinder.Name = FieldName;
             *  var CanGet = DynamicSource.TryGetMember(MemberBinder, out Value);
             *  Result = new Tuple<bool, object>(CanGet, Value);
             * }
             * else */

            if (SourceObject is IDynamicMetaObjectProvider)
            {
                // EFFECTIVE ALTERNATIVE (ALBEIT SLOW, HENCE THE CACHING)
                var QualifiedName = SourceObject.GetType().FullName + General.STR_SEPARATOR + FieldName;

                CallSite <Func <CallSite, object, object> > CallingSite = null;

                if (CachedCallSites.ContainsKey(QualifiedName))
                {
                    CallingSite = CachedCallSites[QualifiedName];
                }
                else
                {
                    var MemberBinder = Microsoft.CSharp.RuntimeBinder.Binder.GetMember(
                        Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.None,
                        FieldName, SourceObject.GetType(),
                        Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(
                            Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.None, null).IntoArray());
                    CallingSite = CallSite <Func <CallSite, object, object> > .Create(MemberBinder);

                    CachedCallSites.Add(QualifiedName, CallingSite);
                }

                try
                {
                    Result = Tuple.Create(true, CallingSite.Target(CallingSite, SourceObject));
                }
                catch
                {
                    Result = Tuple.Create(false, (object)null);
                }

                return(Result);
            }
            else
            {
                Result = (new Tuple <bool, object>(FieldData != null, FieldData != null ? FieldData.GetValue(SourceObject) : null));
            }

            return(Result);
        }
Esempio n. 19
0
 public static BigInteger ConvertToBigInteger(object value)
 {
     return(_bigIntSite.Target(_bigIntSite, value));
 }
Esempio n. 20
0
        /// <summary>
        /// Gets the member name from the object obj.  Throws an exception if the member does not exist or is write-only.
        /// </summary>
        public object GetMember(object obj, string name, bool ignoreCase)
        {
            CallSite <Func <CallSite, object, object> > site = GetOrCreateSite <object, object>(_lc.CreateGetMemberBinder(name, ignoreCase));

            return(site.Target(site, obj));
        }
Esempio n. 21
0
 public static Complex ConvertToComplex(object value)
 {
     return(_complexSite.Target(_complexSite, value));
 }
Esempio n. 22
0
        /// <summary>
        /// Removes the member name from the object obj.  Returns true if the member was successfully removed
        /// or false if the member does not exist.
        /// </summary>
        public void RemoveMember(object obj, string name, bool ignoreCase)
        {
            CallSite <Action <CallSite, object> > site = GetOrCreateActionSite <object>(_lc.CreateDeleteMemberBinder(name, ignoreCase));

            site.Target(site, obj);
        }
Esempio n. 23
0
 public static SByte ConvertToSByte(object value)
 {
     return(_sbyteSite.Target(_sbyteSite, value));
 }
Esempio n. 24
0
        /// <summary>
        /// Sets the member name on object obj to value.  This overload can be used to avoid
        /// boxing and casting of strongly typed members.
        /// </summary>
        public void SetMember <T>(object obj, string name, T value, bool ignoreCase)
        {
            CallSite <Func <CallSite, object, T, object> > site = GetOrCreateSite <object, T, object>(_lc.CreateSetMemberBinder(name, ignoreCase));

            site.Target(site, obj, value);
        }
Esempio n. 25
0
 public static UInt64 ConvertToUInt64(object value)
 {
     return(_uint64Site.Target(_uint64Site, value));
 }
Esempio n. 26
0
        /// <summary>
        /// Convers the object obj to the type T including implicit conversions.
        /// </summary>
        public T ImplicitConvertTo <T>(object obj)
        {
            CallSite <Func <CallSite, object, T> > site = GetOrCreateSite <object, T>(_lc.CreateConvertBinder(typeof(T), false));

            return(site.Target(site, obj));
        }
Esempio n. 27
0
 public static Decimal ConvertToDecimal(object value)
 {
     return(_decimalSite.Target(_decimalSite, value));
 }
Esempio n. 28
0
        /// <summary>
        /// Converts the object obj to the type type including implicit conversions.
        /// </summary>
        public object ImplicitConvertTo(object obj, Type type)
        {
            CallSite <Func <CallSite, object, object> > site = GetOrCreateSite <object, object>(_lc.CreateConvertBinder(type, false));

            return(site.Target(site, obj));
        }
Esempio n. 29
0
 internal static Char ExplicitConvertToChar(object value)
 {
     return(_explicitCharSite.Target(_explicitCharSite, value));
 }
Esempio n. 30
0
 public static object Allocate(RubyClass /*!*/ classObj)
 {
     return(AllocateSharedSite.Target(AllocateSharedSite, classObj.Context, classObj));
 }