Invoke() private method

private Invoke ( Object obj, BindingFlags options, Binder binder, Object parameters, CultureInfo culture ) : Object
obj Object
options BindingFlags
binder Binder
parameters Object
culture System.Globalization.CultureInfo
return Object
 internal override Object Evaluate(){
   Object v1 = this.operand1.Evaluate();
   MethodInfo opTrue = null;
   Type t1 = null;
   if (v1 != null && !(v1 is IConvertible)){
     t1 = v1.GetType();
     opTrue = t1.GetMethod("op_True", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{t1}, null);
     if (opTrue == null || (opTrue.Attributes & MethodAttributes.SpecialName) == 0 || opTrue.ReturnType != Typeob.Boolean)
       opTrue = null;
   }
   if (opTrue == null){
     if (Convert.ToBoolean(v1))
       return v1;
     return this.operand2.Evaluate();
   }
   opTrue = new JSMethodInfo(opTrue);
   if ((bool)opTrue.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{v1}, null))
     return v1;
   Object v2 = this.operand2.Evaluate();
   Type t2 = null;
   if (v2 != null && !(v2 is IConvertible)){
     t2 = v2.GetType();
     if (t1 == t2){
       MethodInfo bitwiseOr = t1.GetMethod("op_BitwiseOr", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{t1, t1}, null);
       if (bitwiseOr != null && (bitwiseOr.Attributes & MethodAttributes.SpecialName) != 0){
         bitwiseOr = new JSMethodInfo(bitwiseOr);
         return bitwiseOr.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{v1, v2}, null);
       }
     }
   }
   return v2;    
 } 
Beispiel #2
0
        internal override bool Delete()
        {
            Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
            int      n  = actual_arguments.Length;
            Object   ob = this.func.Evaluate();

            if (ob == null)
            {
                return(true);        //As per the standard, not backwards compatible with JS5
            }
            if (n == 0)
            {
                return(true);
            }
            Type       obType   = ob.GetType();
            MethodInfo deleteOp = obType.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static,
                                                   null, new Type[] { obType, Typeob.ArrayOfObject }, null);

            if (deleteOp == null || (deleteOp.Attributes & MethodAttributes.SpecialName) == 0 || deleteOp.ReturnType != Typeob.Boolean)
            {
                return(LateBinding.DeleteMember(ob, Convert.ToString(actual_arguments[n - 1])));
            }
            else
            {
                deleteOp = new JSMethodInfo(deleteOp);
                return((bool)deleteOp.Invoke(null, new Object[] { ob, actual_arguments }));
            }
        }
Beispiel #3
0
        internal override Object Evaluate()
        {
            Object     v1     = this.operand1.Evaluate();
            MethodInfo opTrue = null;
            Type       t1     = null;

            if (v1 != null && !(v1 is IConvertible))
            {
                t1     = v1.GetType();
                opTrue = t1.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { t1 }, null);
                if (opTrue == null || (opTrue.Attributes & MethodAttributes.SpecialName) == 0 || opTrue.ReturnType != Typeob.Boolean)
                {
                    opTrue = null;
                }
            }
            if (opTrue == null)
            {
                if (Convert.ToBoolean(v1))
                {
                    return(v1);
                }
                return(this.operand2.Evaluate());
            }
            opTrue = new JSMethodInfo(opTrue);
            if ((bool)opTrue.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[] { v1 }, null))
            {
                return(v1);
            }
            Object v2 = this.operand2.Evaluate();
            Type   t2 = null;

            if (v2 != null && !(v2 is IConvertible))
            {
                t2 = v2.GetType();
                if (t1 == t2)
                {
                    MethodInfo bitwiseOr = t1.GetMethod("op_BitwiseOr", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { t1, t1 }, null);
                    if (bitwiseOr != null && (bitwiseOr.Attributes & MethodAttributes.SpecialName) != 0)
                    {
                        bitwiseOr = new JSMethodInfo(bitwiseOr);
                        return(bitwiseOr.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[] { v1, v2 }, null));
                    }
                }
            }
            return(v2);
        }
Beispiel #4
0
        internal override object Evaluate()
        {
            object     obj2   = base.operand1.Evaluate();
            MethodInfo method = null;
            Type       type   = null;

            if ((obj2 != null) && !(obj2 is IConvertible))
            {
                type   = obj2.GetType();
                method = type.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type }, null);
                if (((method == null) || ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.PrivateScope)) || (method.ReturnType != Typeob.Boolean))
                {
                    method = null;
                }
            }
            if (method == null)
            {
                if (Microsoft.JScript.Convert.ToBoolean(obj2))
                {
                    return(obj2);
                }
                return(base.operand2.Evaluate());
            }
            method = new JSMethodInfo(method);
            if ((bool)method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { obj2 }, null))
            {
                return(obj2);
            }
            object obj3  = base.operand2.Evaluate();
            Type   type2 = null;

            if ((obj3 != null) && !(obj3 is IConvertible))
            {
                type2 = obj3.GetType();
                if (type == type2)
                {
                    MethodInfo info2 = type.GetMethod("op_BitwiseOr", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type, type }, null);
                    if ((info2 != null) && ((info2.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
                    {
                        info2 = new JSMethodInfo(info2);
                        return(info2.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { obj2, obj3 }, null));
                    }
                }
            }
            return(obj3);
        }
 internal override object Evaluate()
 {
     object obj2 = base.operand1.Evaluate();
     MethodInfo method = null;
     Type type = null;
     if ((obj2 != null) && !(obj2 is IConvertible))
     {
         type = obj2.GetType();
         method = type.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type }, null);
         if (((method == null) || ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.PrivateScope)) || (method.ReturnType != Typeob.Boolean))
         {
             method = null;
         }
     }
     if (method == null)
     {
         if (Microsoft.JScript.Convert.ToBoolean(obj2))
         {
             return obj2;
         }
         return base.operand2.Evaluate();
     }
     method = new JSMethodInfo(method);
     if ((bool) method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { obj2 }, null))
     {
         return obj2;
     }
     object obj3 = base.operand2.Evaluate();
     Type type2 = null;
     if ((obj3 != null) && !(obj3 is IConvertible))
     {
         type2 = obj3.GetType();
         if (type == type2)
         {
             MethodInfo info2 = type.GetMethod("op_BitwiseOr", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type, type }, null);
             if ((info2 != null) && ((info2.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
             {
                 info2 = new JSMethodInfo(info2);
                 return info2.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { obj2, obj3 }, null);
             }
         }
     }
     return obj3;
 }
Beispiel #6
0
        internal override bool Delete()
        {
            object[] objArray = (this.args == null) ? null : this.args.EvaluateAsArray();
            int      length   = objArray.Length;
            object   obj2     = this.func.Evaluate();

            if (obj2 == null)
            {
                return(true);
            }
            if (length == 0)
            {
                return(true);
            }
            Type       type   = obj2.GetType();
            MethodInfo method = type.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type, Typeob.ArrayOfObject }, null);

            if (((method == null) || ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.PrivateScope)) || (method.ReturnType != Typeob.Boolean))
            {
                return(LateBinding.DeleteMember(obj2, Microsoft.JScript.Convert.ToString(objArray[length - 1])));
            }
            method = new JSMethodInfo(method);
            return((bool)method.Invoke(null, new object[] { obj2, objArray }));
        }
Beispiel #7
0
      private static Object ToPrimitive(Object value, PreferredType preferredType, IConvertible ic, TypeCode tcode){
        switch (tcode){
          case TypeCode.Object:
            System.Array arr = value as System.Array;
            if (arr != null && arr.Rank == 1) value = new ArrayWrapper(ArrayPrototype.ob, arr, true);
            if (value is ScriptObject){
              Object result = ((ScriptObject)value).GetDefaultValue(preferredType);
              if (Convert.GetTypeCode(result) != TypeCode.Object)
                return result;
              else if (value == result && preferredType == PreferredType.String || preferredType == PreferredType.LocaleString){
                if (value is JSObject){
                  ScriptObject proto = ((JSObject)value).GetParent();
                  if (proto is ClassScope)
                    return ((ClassScope)proto).GetFullName();
                  return "[object Object]";
                }
                return value.ToString();
              }else
                throw new JScriptException(JSError.TypeMismatch);
            }else if (value is Missing || value is System.Reflection.Missing)
              return null;
            else{
              IReflect ir;
              if (value is IReflect && !(value is Type))
                ir = (IReflect)value;
              else
                ir = value.GetType();

              //Look for an op_Explicit conversion to String or Double (this always fails for IDispatch/Ex objects
              MethodInfo meth = null;
              if (preferredType == PreferredType.String || preferredType == PreferredType.LocaleString)
                meth = Convert.GetToXXXXMethod(ir, Typeob.String, true);
              else{
                meth = Convert.GetToXXXXMethod(ir, Typeob.Double, true);
                if (meth == null)
                  meth = Convert.GetToXXXXMethod(ir, Typeob.Int64, true);
                if (meth == null)
                  meth = Convert.GetToXXXXMethod(ir, Typeob.UInt64, true);
              }
              if (meth != null){
                meth = new JSMethodInfo(meth);
                return meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
              }

              //Invoke the default method/property or get the value of the default field. If an exception is thrown
              //because the target doesn't have a non-paramterized default member, mask it and execute the
              //default handling.
              try{
                try{
                  MemberInfo member = LateBinding.SelectMember(JSBinder.GetDefaultMembers(ir));
                  if (member != null){
                    switch(member.MemberType){
                      case MemberTypes.Field: return ((FieldInfo)member).GetValue(value);
                      case MemberTypes.Method: return ((MethodInfo)member).Invoke(value, new Object[0]);
                      case MemberTypes.Property: return JSProperty.GetValue((PropertyInfo)member, value, null);
                      case MemberTypes.Event: return null;
                      case MemberTypes.NestedType: return member;
                    }
                  }
                  
                  
                  return ir.InvokeMember(String.Empty, BindingFlags.ExactBinding|BindingFlags.SuppressChangeType|
                                                       BindingFlags.InvokeMethod|BindingFlags.GetProperty|BindingFlags.GetField,
                                         null, value, new Object[0], null, null, new String[0]);
                }catch(TargetInvocationException e){
                  throw e.InnerException;
                }
              }catch(ArgumentException){
              }catch(IndexOutOfRangeException){
              }catch(MissingMemberException){
              }catch(TargetParameterCountException){
              }

              if (preferredType != PreferredType.Number)
                if (value is Char[])
                  return new System.String((Char[])value);
                else
                  return value.ToString();
              return value;
            }
          case TypeCode.DateTime:
            return DateConstructor.ob.Construct(ic.ToDateTime(null)).GetDefaultValue(preferredType);
        }
        return value;
      }
Beispiel #8
0
 internal static bool ToBoolean(Object value, IConvertible ic){
   switch (Convert.GetTypeCode(value, ic)){
     case TypeCode.Empty: return false;
     case TypeCode.Object:
       if (value is Missing || value is System.Reflection.Missing) return false;
       Type t = value.GetType();
       MethodInfo meth = t.GetMethod("op_True", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{t}, null);
       if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0 && meth.ReturnType == Typeob.Boolean){
         meth = new JSMethodInfo(meth);
         return (bool)meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
       }
       return true;
     case TypeCode.DBNull: return false;
     case TypeCode.Boolean: return ic.ToBoolean(null);
     case TypeCode.Char: return ic.ToChar(null) != (Char)0;
     case TypeCode.SByte:
     case TypeCode.Byte:
     case TypeCode.Int16:
     case TypeCode.UInt16:
     case TypeCode.Int32: return ic.ToInt32(null) != 0;
     case TypeCode.UInt32:
     case TypeCode.Int64: return ic.ToInt64(null) != 0;
     case TypeCode.UInt64: return ic.ToUInt64(null) != 0;
     case TypeCode.Single:
     case TypeCode.Double:
       double d = ic.ToDouble(null);
       if (d != d) return false; else return d != 0;
     case TypeCode.Decimal: return ic.ToDecimal(null) != (Decimal)0;
     case TypeCode.DateTime: return true;
     case TypeCode.String: return ic.ToString(null).Length != 0;
   }
   return false; //should never get here
 }
Beispiel #9
0
 public static Object CoerceT(Object value, Type t, bool explicitOK){
   if (t == Typeob.Object) return value;
   if (t == Typeob.String && value is String) return value;
   if (t.IsEnum && !(t is EnumBuilder) && !(t is TypeBuilder)){
     IConvertible ic = Convert.GetIConvertible(value);
     TypeCode vc = Convert.GetTypeCode(value, ic);
     if (vc == TypeCode.String)
       return Enum.Parse(t, ic.ToString());
     else{
       if (!explicitOK && vc != TypeCode.Empty){
         Type vty = value.GetType();
         if (vty.IsEnum)
           if (vty != t) throw new JScriptException(JSError.TypeMismatch); else return value;
       }
       return Enum.ToObject(t, Convert.CoerceT(value, Convert.GetUnderlyingType(t), explicitOK));
     }
   }
   TypeCode c2 = Type.GetTypeCode(t);
   if (c2 != TypeCode.Object)
     return Convert.Coerce2(value, c2, explicitOK);
   if (value is ConcatString) value = value.ToString();
   if (value == null || (value == DBNull.Value && t != Typeob.Object) || value is Missing || value is System.Reflection.Missing)
     if (t.IsValueType)
       return Activator.CreateInstance(t);
     else
       return null;
   else if (t.IsAssignableFrom(value.GetType()))
     return value;
   else if (typeof(Delegate).IsAssignableFrom(t)){
     if (value is Closure)
       return ((Closure)value).ConvertToDelegate(t);
     else if (value is FunctionWrapper)
       return ((FunctionWrapper)value).ConvertToDelegate(t);
     else if (value is FunctionObject) //called at compile-time from ConstantWrapper
       return value; //Do nothing, ConstantWrapper will do the right thing.
   }else if (value is ArrayObject && Typeob.Array.IsAssignableFrom(t))
     return ((ArrayObject)value).ToNativeArray(t.GetElementType());
   else if (value is Array && t == Typeob.ArrayObject && ((Array)value).Rank == 1){
     if (Globals.contextEngine == null){
       Globals.contextEngine = new VsaEngine(true); //ASP+ case
       Globals.contextEngine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite());
     }
     return Globals.contextEngine.GetOriginalArrayConstructor().ConstructWrapper((Array)value);
   }else if (value is ClassScope && t == Typeob.Type)
     return ((ClassScope)value).GetTypeBuilderOrEnumBuilder();
   else if (value is TypedArray && t == Typeob.Type)
     return ((TypedArray)value).ToType();
   //Look for a suitable op_Implicit or op_Explicit conversion
   Type source_type = value.GetType();
   MethodInfo meth = null;
   if (explicitOK){
     meth = t.GetMethod("op_Explicit", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{source_type}, null);
     if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0){
       meth = new JSMethodInfo(meth);
       return meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
     }
     meth = Convert.GetToXXXXMethod(source_type, t, explicitOK);
     if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0){
       meth = new JSMethodInfo(meth);
       if (meth.IsStatic)
         return meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
       else
         return meth.Invoke(value, BindingFlags.SuppressChangeType, null, new Object[]{}, null);
     }
   }
   meth = t.GetMethod("op_Implicit", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{source_type}, null);
   if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0){
     meth = new JSMethodInfo(meth);
     return meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
   }
   meth = Convert.GetToXXXXMethod(source_type, t, false);
   if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0){
     meth = new JSMethodInfo(meth);
     if (meth.IsStatic)
       return meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
     else
       return meth.Invoke(value, BindingFlags.SuppressChangeType, null, new Object[]{}, null);
   }
   if (t.IsByRef)
     return Convert.CoerceT(value, t.GetElementType());
   Type vt = value.GetType();
   throw new JScriptException(JSError.TypeMismatch);
 }
Beispiel #10
0
 internal override bool Delete(){
   Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
   int n = actual_arguments.Length;
   Object ob = this.func.Evaluate();
   if (ob == null) return true; //As per the standard, not backwards compatible with JS5
   if (n == 0) return true;
   Type obType = ob.GetType();
   MethodInfo deleteOp = obType.GetMethod("op_Delete", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, 
                                           null, new Type[]{obType, typeof(Object[])}, null);
   if (deleteOp == null || (deleteOp.Attributes & MethodAttributes.SpecialName) == 0 || deleteOp.ReturnType != Typeob.Boolean)
     return LateBinding.DeleteMember(ob, Convert.ToString(actual_arguments[n-1]));
   else{
     deleteOp = new JSMethodInfo(deleteOp);
     return (bool)deleteOp.Invoke(null, new Object[]{ob, actual_arguments});
   }
 }
 internal override bool Delete()
 {
     object[] objArray = (this.args == null) ? null : this.args.EvaluateAsArray();
     int length = objArray.Length;
     object obj2 = this.func.Evaluate();
     if (obj2 == null)
     {
         return true;
     }
     if (length == 0)
     {
         return true;
     }
     Type type = obj2.GetType();
     MethodInfo method = type.GetMethod("op_Delete", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type, Typeob.ArrayOfObject }, null);
     if (((method == null) || ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.PrivateScope)) || (method.ReturnType != Typeob.Boolean))
     {
         return LateBinding.DeleteMember(obj2, Microsoft.JScript.Convert.ToString(objArray[length - 1]));
     }
     method = new JSMethodInfo(method);
     return (bool) method.Invoke(null, new object[] { obj2, objArray });
 }
        private static object ToPrimitive(object value, PreferredType preferredType, IConvertible ic, TypeCode tcode)
        {
            IReflect reflect;
            TypeCode code = tcode;
            if (code != TypeCode.Object)
            {
                if (code == TypeCode.DateTime)
                {
                    return DateConstructor.ob.Construct(ic.ToDateTime(null)).GetDefaultValue(preferredType);
                }
                return value;
            }
            Array array = value as Array;
            if ((array != null) && (array.Rank == 1))
            {
                value = new ArrayWrapper(ArrayPrototype.ob, array, true);
            }
            if (value is ScriptObject)
            {
                object defaultValue = ((ScriptObject) value).GetDefaultValue(preferredType);
                if (GetTypeCode(defaultValue) != TypeCode.Object)
                {
                    return defaultValue;
                }
                if (((value != defaultValue) || (preferredType != PreferredType.String)) && (preferredType != PreferredType.LocaleString))
                {
                    throw new JScriptException(JSError.TypeMismatch);
                }
                if (!(value is JSObject))
                {
                    return value.ToString();
                }
                ScriptObject parent = ((JSObject) value).GetParent();
                if (parent is ClassScope)
                {
                    return ((ClassScope) parent).GetFullName();
                }
                return "[object Object]";
            }
            if ((value is Microsoft.JScript.Missing) || (value is System.Reflection.Missing))
            {
                return null;
            }
            if ((value is IReflect) && !(value is Type))
            {
                reflect = (IReflect) value;
            }
            else
            {
                reflect = value.GetType();
            }
            MethodInfo method = null;
            if ((preferredType == PreferredType.String) || (preferredType == PreferredType.LocaleString))
            {
                method = GetToXXXXMethod(reflect, typeof(string), true);
            }
            else
            {
                method = GetToXXXXMethod(reflect, typeof(double), true);
                if (method == null)
                {
                    method = GetToXXXXMethod(reflect, typeof(long), true);
                }
                if (method == null)
                {
                    method = GetToXXXXMethod(reflect, typeof(ulong), true);
                }
            }
            if (method != null)
            {
                method = new JSMethodInfo(method);
                return method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
            }
            try
            {
                try
                {
                    MemberInfo info2 = LateBinding.SelectMember(JSBinder.GetDefaultMembers(Runtime.TypeRefs, reflect));
                    if (info2 != null)
                    {
                        switch (info2.MemberType)
                        {
                            case MemberTypes.Property:
                                return JSProperty.GetValue((PropertyInfo) info2, value, null);

                            case MemberTypes.NestedType:
                                return info2;

                            case MemberTypes.Event:
                                return null;

                            case MemberTypes.Field:
                                return ((FieldInfo) info2).GetValue(value);

                            case MemberTypes.Method:
                                return ((MethodInfo) info2).Invoke(value, new object[0]);
                        }
                    }
                    if (value == reflect)
                    {
                        Type type = value.GetType();
                        if (TypeReflector.GetTypeReflectorFor(type).Is__ComObject() && (!VsaEngine.executeForJSEE || !(value is IDebuggerObject)))
                        {
                            reflect = type;
                        }
                    }
                    if (VsaEngine.executeForJSEE)
                    {
                        IDebuggerObject obj4 = reflect as IDebuggerObject;
                        if (obj4 != null)
                        {
                            if (!obj4.IsScriptObject())
                            {
                                throw new JScriptException(JSError.NonSupportedInDebugger);
                            }
                            return reflect.InvokeMember("< JScript-" + preferredType.ToString() + " >", BindingFlags.SuppressChangeType | BindingFlags.ExactBinding | BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.InvokeMethod, null, value, new object[0], null, null, new string[0]);
                        }
                    }
                    return reflect.InvokeMember(string.Empty, BindingFlags.SuppressChangeType | BindingFlags.ExactBinding | BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.InvokeMethod, null, value, new object[0], null, null, new string[0]);
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
            }
            catch (ArgumentException)
            {
            }
            catch (IndexOutOfRangeException)
            {
            }
            catch (MissingMemberException)
            {
            }
            catch (SecurityException)
            {
            }
            catch (TargetParameterCountException)
            {
            }
            catch (COMException exception2)
            {
                if (exception2.ErrorCode != -2147352573)
                {
                    throw exception2;
                }
            }
            if (preferredType == PreferredType.Number)
            {
                return value;
            }
            if (value.GetType().IsCOMObject)
            {
                return "ActiveXObject";
            }
            if (value is char[])
            {
                return new string((char[]) value);
            }
            return value.ToString();
        }
        internal static bool ToBoolean(object value, IConvertible ic)
        {
            switch (GetTypeCode(value, ic))
            {
                case TypeCode.Empty:
                    return false;

                case TypeCode.Object:
                {
                    if ((value is Microsoft.JScript.Missing) || (value is System.Reflection.Missing))
                    {
                        return false;
                    }
                    Type type = value.GetType();
                    MethodInfo method = type.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type }, null);
                    if (((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope)) && (method.ReturnType == typeof(bool)))
                    {
                        method = new JSMethodInfo(method);
                        return (bool) method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
                    }
                    return true;
                }
                case TypeCode.DBNull:
                    return false;

                case TypeCode.Boolean:
                    return ic.ToBoolean(null);

                case TypeCode.Char:
                    return (ic.ToChar(null) != '\0');

                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                    return (ic.ToInt32(null) != 0);

                case TypeCode.UInt32:
                case TypeCode.Int64:
                    return (ic.ToInt64(null) != 0L);

                case TypeCode.UInt64:
                    return (ic.ToUInt64(null) != 0L);

                case TypeCode.Single:
                case TypeCode.Double:
                {
                    double num = ic.ToDouble(null);
                    return ((num == num) && !(num == 0.0));
                }
                case TypeCode.Decimal:
                    return (ic.ToDecimal(null) != 0M);

                case TypeCode.DateTime:
                    return true;

                case TypeCode.String:
                    return (ic.ToString(null).Length != 0);
            }
            return false;
        }
 public static object CoerceT(object value, Type t, bool explicitOK)
 {
     if (t != typeof(object))
     {
         if ((t == typeof(string)) && (value is string))
         {
             return value;
         }
         if ((t.IsEnum && !(t is EnumBuilder)) && !(t is TypeBuilder))
         {
             IConvertible iConvertible = GetIConvertible(value);
             TypeCode code = GetTypeCode(value, iConvertible);
             if (code == TypeCode.String)
             {
                 return Enum.Parse(t, iConvertible.ToString(CultureInfo.InvariantCulture));
             }
             if (!explicitOK && (code != TypeCode.Empty))
             {
                 Type type = value.GetType();
                 if (type.IsEnum)
                 {
                     if (type != t)
                     {
                         throw new JScriptException(JSError.TypeMismatch);
                     }
                     return value;
                 }
             }
             return Enum.ToObject(t, CoerceT(value, GetUnderlyingType(t), explicitOK));
         }
         TypeCode typeCode = Type.GetTypeCode(t);
         if (typeCode != TypeCode.Object)
         {
             return Coerce2(value, typeCode, explicitOK);
         }
         if (value is ConcatString)
         {
             value = value.ToString();
         }
         if (((value == null) || ((value == DBNull.Value) && (t != typeof(object)))) || ((value is Microsoft.JScript.Missing) || (value is System.Reflection.Missing)))
         {
             if (!t.IsValueType)
             {
                 return null;
             }
             if (!t.IsPublic && (t.Assembly == typeof(ActiveXObjectConstructor).Assembly))
             {
                 throw new JScriptException(JSError.CantCreateObject);
             }
             return Activator.CreateInstance(t);
         }
         if (t.IsAssignableFrom(value.GetType()))
         {
             return value;
         }
         if (typeof(Delegate).IsAssignableFrom(t))
         {
             if (value is Closure)
             {
                 return ((Closure) value).ConvertToDelegate(t);
             }
             if (value is FunctionWrapper)
             {
                 return ((FunctionWrapper) value).ConvertToDelegate(t);
             }
             if (value is FunctionObject)
             {
                 return value;
             }
         }
         else
         {
             if ((value is ArrayObject) && typeof(Array).IsAssignableFrom(t))
             {
                 return ((ArrayObject) value).ToNativeArray(t.GetElementType());
             }
             if (((value is Array) && (t == typeof(ArrayObject))) && (((Array) value).Rank == 1))
             {
                 if (Globals.contextEngine == null)
                 {
                     Globals.contextEngine = new VsaEngine(true);
                     Globals.contextEngine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite());
                 }
                 return Globals.contextEngine.GetOriginalArrayConstructor().ConstructWrapper((Array) value);
             }
             if ((value is ClassScope) && (t == typeof(Type)))
             {
                 return ((ClassScope) value).GetTypeBuilderOrEnumBuilder();
             }
             if ((value is TypedArray) && (t == typeof(Type)))
             {
                 return ((TypedArray) value).ToType();
             }
         }
         Type ir = value.GetType();
         MethodInfo method = null;
         if (explicitOK)
         {
             method = t.GetMethod("op_Explicit", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { ir }, null);
             if ((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
             {
                 method = new JSMethodInfo(method);
                 return method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
             }
             method = GetToXXXXMethod(ir, t, explicitOK);
             if ((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
             {
                 method = new JSMethodInfo(method);
                 if (method.IsStatic)
                 {
                     return method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
                 }
                 return method.Invoke(value, BindingFlags.SuppressChangeType, null, new object[0], null);
             }
         }
         method = t.GetMethod("op_Implicit", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { ir }, null);
         if ((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
         {
             method = new JSMethodInfo(method);
             return method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
         }
         method = GetToXXXXMethod(ir, t, false);
         if ((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope))
         {
             method = new JSMethodInfo(method);
             if (method.IsStatic)
             {
                 return method.Invoke(null, BindingFlags.SuppressChangeType, null, new object[] { value }, null);
             }
             return method.Invoke(value, BindingFlags.SuppressChangeType, null, new object[0], null);
         }
         if (t.IsByRef)
         {
             return CoerceT(value, t.GetElementType());
         }
         if (!value.GetType().IsCOMObject)
         {
             throw new JScriptException(JSError.TypeMismatch);
         }
     }
     return value;
 }