예제 #1
0
        public static bool Equals(Expose left, object right)
        {
            try
            {
                return((bool)left.Call("op_Equality", right).Value);
            }
            catch
            { }

            try
            {
                return(ToDecimal(left) == ToDecimal(right));
            }
            catch
            { }

            try
            {
                return((bool)left.Call("Equals", right).Value);
            }
            catch
            { }

            object lv = ReferenceEquals(left, null) ? null : left.Value;
            object rv = right;

            return(ReferenceEquals(lv, null) ? ReferenceEquals(rv, null) : lv.Equals(rv));
        }
예제 #2
0
        public static bool Equals(Expose left, Expose right)
        {
            object lv = ReferenceEquals(left, null) ? null : left.Value;
            object rv = ReferenceEquals(right, null) ? null : right.Value;

            return(ReferenceEquals(lv, null) ? ReferenceEquals(rv, null) : Expose.Equals(left, rv));
        }
예제 #3
0
        static Expose Addition(Expose left, object right)
        {
            try
            {
                if (IsNumber(left) && IsNumber(right))
                {
                    var d = ToDecimal(left) + ToDecimal(right);
                    return(Expose.FromObject(ToDecimal(left) + ToDecimal(right)));
                }
                return(Expose.FromType(left.Type).Call("op_Addition", left.Value, right));
            }
            catch
            {
            }

            object lv = ReferenceEquals(left, null) ? null : left.Value;

            if (lv is string || right is string)
            {
                string ls = ReferenceEquals(lv, null) ? "" : lv.ToString();
                string rs = ReferenceEquals(right, null) ? "" : right.ToString();
                return(Expose.FromObject(ls + rs));
            }

            try
            {
                return(Expose.FromObject(ToDecimal(left) + ToDecimal(right)));
            }
            catch
            {
            }
            return(null);
        }
예제 #4
0
        public Expose Get(string memberName)
        {
            var pi = Type.GetProperty(memberName, Flag | BindingFlags.GetProperty);

            if (pi != null)
            {
                return(Expose.FromObject(pi.GetValue(Value)));
            }
            var fi = Type.GetField(memberName, Flag | BindingFlags.GetField);

            if (fi != null)
            {
                return(Expose.FromObject(fi.GetValue(Value)));
            }

            // Get with indexer
            try
            {
                return(Get(new[] { memberName }));
            }
            catch
            {
                throw new MissingMemberException(Type.Name, memberName);
            }
        }
예제 #5
0
 public IEnumerator GetEnumerator()
 {
     if (Value is IEnumerable)
     {
         foreach (object o in Value as IEnumerable)
         {
             yield return(Expose.FromObject(o));
         }
     }
     yield break;
 }
예제 #6
0
        public Expose Get(object[] index)
        {
            var pi = Type.GetProperty(Type.GetCustomAttribute <DefaultMemberAttribute>().MemberName, index.Select(x => x.GetType()).ToArray());

            if (pi != null)
            {
                return(Expose.FromObject(pi.GetValue(Value, index)));
            }

            throw new MissingMemberException(Type.Name, "Indexer");
        }
예제 #7
0
        //public static Type GetType<T>(params Type[] genericTypes)
        //{
        //	return GetType(new [] { typeof(T) }.Concat( genericTypes).ToArray());
        //}

        //public static Type GetType<T>(params string[] genericTypes)
        //{
        //return GetType(new [] { typeof(T).AssemblyQualifiedName }.Concat( genericTypes).ToArray());
        //}

        //public static Type GetType(params string[] genericTypes)
        //{
        //    return GetType(genericTypes.Select(x => GetType(x)).ToArray());
        //}

        //public static Type GetType(params Type[] genericTypes)
        //{
        //    if (genericTypes.Length == 0)
        //    {
        //        throw new ArgumentException("Requires one or more Type objects", "genericTypes");
        //    }
        //    else if (genericTypes.Length == 1)
        //    {
        //        if (!genericTypes[0].IsGenericTypeDefinition)
        //        {
        //            return genericTypes[0];
        //        }
        //        throw new ArgumentException("Missing generic type parameter", "genericTypes");
        //    }
        //    else
        //    {
        //        if (genericTypes[0].IsGenericTypeDefinition)
        //        {
        //            return genericTypes[0].MakeGenericType(genericTypes.Skip(1).ToArray());
        //        }
        //        throw new ArgumentException("Missing generic type definition", "genericTypes");
        //    }
        //}


        //static Type ToBaseClass(Type type)
        //{
        //    if (!type.IsGenericType || !type.IsConstructedGenericType || type.IsGenericTypeDefinition)
        //        return type;

        //    if (type.GenericTypeArguments[0].IsGenericParameter)
        //        return type.GetGenericTypeDefinition();

        //    return type;
        //}

        static bool TryInvoke(string methodName, object instance, IEnumerable <MethodInfo> methodInfos, object[] args, out Expose result)
        {
            var methodInfo = methodInfos.FirstOrDefault(x => x.Name == methodName && IsInvokable(x, args));

            if (methodInfo != null)
            {
                result = Expose.FromObject(methodInfo.Invoke(instance, args));
                return(true);
            }
            result = null;
            return(false);
        }
예제 #8
0
        //public Expose Call<T0>(string methodName, params object[] args)
        //{
        //    return Call(new[] { typeof(T0) }, methodName, args);
        //}

        //public Expose Call<T0, T1>(string methodName, params object[] args)
        //{
        //    return Call(new[] { typeof(T0), typeof(T1) }, methodName, args);
        //}

        //public Expose Call<T0, T1, T2>(string methodName, params object[] args)
        //{
        //    return Call(new[] { typeof(T0), typeof(T1), typeof(T2) }, methodName, args);
        //}

        //public Expose Call<T0, T1, T2, T3>(string methodName, params object[] args)
        //{
        //    return Call(new[] { typeof(T0), typeof(T1), typeof(T2), typeof(T3) }, methodName, args);
        //}


        //public Expose Call(Type[] genericTypes, string methodName, params object[] args)
        //{
        //    args = args.Select(x => x is Expose ? ((Expose)x).Value : x).ToArray();

        //    // Find method
        //    Expose result;
        //    if (TryInvoke(methodName, Value, Type.GetMethods(Flag | BindingFlags.InvokeMethod), genericTypes, args, out result))
        //    {
        //        return result;
        //    }

        //    args = new[] { Value }.Concat(args).ToArray();
        //    if (Value != null && TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), genericTypes, args, out result))
        //    {
        //        return result;
        //    }

        //    throw new MissingMemberException(Type.Name, methodName);
        //}


        public Expose Call(string methodName, params object[] args)
        {
            args = args.Select(x => x is Expose ? ((Expose)x).Value : x).ToArray();

            // Find method
            Expose result;

            if (TryInvoke(methodName, Value, Type.GetMethods(Flag | BindingFlags.InvokeMethod), args, out result))
            {
                return(result);
            }

            // Find event
            var fi = Type.GetField(methodName, Flag | BindingFlags.SetField);

            if (fi != null)
            {
                var del = fi.GetValue(Value) as MulticastDelegate;
                if (del != null && IsInvokable(del.Method, args))
                {
                    object lastResult = null;
                    foreach (var h in del.GetInvocationList())
                    {
                        lastResult = h.Method.Invoke(h.Target, args);
                    }
                    return(Expose.FromObject(lastResult));
                }
            }

            // Find operator method
            args = new[] { Value }.Concat(args).ToArray();
            if (TryInvoke(methodName, null, Type.GetMethods(Flag | BindingFlags.InvokeMethod), args, out result))
            {
                return(result);
            }

            // Find extension method
            //if (Value != null
            //    && TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), null, args, out result))
            //{
            //    if (
            //        TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), null, args, out result)
            //        || TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), new[] { Type }, args, out result)
            //    )
            //        return result;
            //}

            throw new MissingMemberException(Type.Name, methodName);
        }
예제 #9
0
        static Expose Subtraction(Expose left, object right)
        {
            try
            {
                return(Expose.FromType(left.Type).Call("op_Subtraction", left.Value, right));
            }
            catch
            { }

            try
            {
                return(Expose.FromObject(ToDecimal(left) - ToDecimal(right)));
            }
            catch
            { }

            return(null);
        }
예제 #10
0
        static bool LessThan(Expose left, object right)
        {
            try
            {
                return((bool)Expose.FromType(left.Type).Call("op_LessThan", left.Value, right).Value);
            }
            catch
            { }

            try
            {
                return(ToDecimal(left) < ToDecimal(right));
            }
            catch
            {
                return(Expose.Compare(left, right) < 0);
            }
        }
예제 #11
0
 public static int Compare(Expose left, object right)
 {
     return(Compare_Impl(ReferenceEquals(left, null) ? null : left.Value, right));
 }
예제 #12
0
        static Expose DoOperation(Expose left, object right, Operation op)
        {
            try
            {
                return(Expose.FromType(left.Type).Call(op.ToString(), left.Value, right));
            }
            catch
            { }

            try
            {
                switch (op)
                {
                case Operation.op_Addition:
                    return(Expose.FromObject(ToDecimal(left) + ToDecimal(right)));

                case Operation.op_Subtraction:
                    return(Expose.FromObject(ToDecimal(left) - ToDecimal(right)));

                case Operation.op_Equality:
                    return(Expose.FromObject(ToDecimal(left) == ToDecimal(right)));

                case Operation.op_Inequality:
                    return(Expose.FromObject(ToDecimal(left) != ToDecimal(right)));

                case Operation.op_GreaterThan:
                    return(Expose.FromObject(ToDecimal(left) > ToDecimal(right)));

                case Operation.op_LessThan:
                    return(Expose.FromObject(ToDecimal(left) < ToDecimal(right)));

                case Operation.op_GreaterThanOrEqual:
                    return(Expose.FromObject(ToDecimal(left) <= ToDecimal(right)));

                case Operation.op_LessThanOrEqual:
                    return(Expose.FromObject(ToDecimal(left) >= ToDecimal(right)));

                case Operation.op_BitwiseAnd:
                    return(Expose.FromObject(ToInt(left) & ToInt(right)));

                case Operation.op_BitwiseOr:
                    return(Expose.FromObject(ToInt(left) | ToInt(right)));

                case Operation.op_Division:
                    return(Expose.FromObject(ToDecimal(left) / ToDecimal(right)));

                case Operation.op_Modulus:
                    return(Expose.FromObject(ToDecimal(left) % ToDecimal(right)));

                case Operation.op_Multiply:
                    return(Expose.FromObject(ToDecimal(left) * ToDecimal(right)));

                case Operation.op_LeftShift:
                    return(Expose.FromObject(ToInt(left) << ToInt(right)));

                case Operation.op_RightShift:
                    return(Expose.FromObject(ToInt(left) >> ToInt(right)));

                case Operation.op_ExclusiveOr:
                    return(Expose.FromObject(ToInt(left) ^ ToInt(right)));

                case Operation.op_UnaryNegation:
                    break;

                case Operation.op_UnaryPlus:
                    break;

                case Operation.op_LogicalNot:
                    break;

                case Operation.op_OnesComplement:
                    break;

                case Operation.op_False:
                    break;

                case Operation.op_True:
                    break;

                case Operation.op_Increment:
                    break;

                case Operation.op_Decrement:
                    break;
                }
            }
            catch
            { }

            return(null);
        }
예제 #13
0
 public static bool operator !=(object left, Expose right)
 {
     return(!Expose.Equals(right, left));
 }
예제 #14
0
 public static Expose operator -(Expose left, Expose right)
 {
     return(Expose.Subtraction(left, right.Value));
 }
예제 #15
0
 public static Expose operator +(Expose left, Expose right)
 {
     return(Expose.Addition(left, right.Value));
 }
예제 #16
0
 public static int Compare(Expose left, Expose right)
 {
     return(Compare_Impl(
                ReferenceEquals(left, null) ? null : left.Value,
                ReferenceEquals(right, null) ? null : right.Value));
 }
예제 #17
0
 public bool Equals(Expose other)
 {
     return(Equals(this, other));
 }
예제 #18
0
 public static Expose operator +(object left, Expose right)
 {
     return(Addition(Expose.FromObject(left), right.Value));
 }
예제 #19
0
 public static bool operator ==(Expose left, Expose right)
 {
     return(Expose.Equals(left, right));
 }
예제 #20
0
 public static Expose operator -(object left, Expose right)
 {
     return(Subtraction(Expose.FromObject(left), right.Value));
 }
예제 #21
0
 public static bool operator !=(Expose left, object right)
 {
     return(!Expose.Equals(left, right));
 }