2009-10-22 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpConvertBinder.cs
index a2269e7c2022db3703de19591fe340aaa5191c0d..031635477d92ddd20f33b030d2c2aa2a29bd895f 100644 (file)
@@ -34,42 +34,16 @@ using Compiler = Mono.CSharp;
 
 namespace Microsoft.CSharp.RuntimeBinder
 {
-       public class CSharpConvertBinder : ConvertBinder
+       class CSharpConvertBinder : ConvertBinder
        {
-               bool is_checked;
+               readonly CSharpBinderFlags flags;
 
-               public CSharpConvertBinder (Type type, CSharpConversionKind conversionKind, bool isChecked)
-                       : base (type, conversionKind == CSharpConversionKind.ExplicitConversion)
+               public CSharpConvertBinder (Type type, CSharpBinderFlags flags)
+                       : base (type, (flags & CSharpBinderFlags.ConvertExplicit) != 0)
                {
-                       this.is_checked = isChecked;
-               }
-               
-               public CSharpConversionKind ConversionKind {
-                       get {
-                               return Explicit ? CSharpConversionKind.ExplicitConversion : CSharpConversionKind.ImplicitConversion;
-                       }
-               }               
-               
-               public override bool Equals (object obj)
-               {
-                       var other = obj as CSharpConvertBinder;
-                       return other != null && other.Type == Type && other.Explicit == Explicit && other.is_checked == is_checked;
+                       this.flags = flags;
                }
 
-               public bool IsChecked {
-                       get {
-                               return is_checked;
-                       }
-               }
-               
-               public override int GetHashCode ()
-               {
-                       return Extensions.HashCode (
-                               Type.GetHashCode (),
-                               Explicit.GetHashCode (),
-                               is_checked.GetHashCode ());
-               }
-               
                public override DynamicMetaObject FallbackConvert (DynamicMetaObject target, DynamicMetaObject errorSuggestion)
                {
                        var expr = CSharpBinder.CreateCompilerExpression (null, target);
@@ -77,13 +51,13 @@ namespace Microsoft.CSharp.RuntimeBinder
                        if (Explicit)
                                expr = new Compiler.Cast (new Compiler.TypeExpression (Type, Compiler.Location.Null), expr);
                        else
-                               expr = new Compiler.ImplicitCast (expr, Type);
+                               expr = new Compiler.ImplicitCast (expr, Type, (flags & CSharpBinderFlags.ConvertArrayIndex) != 0);
 
-                       if (is_checked)
+                       if ((flags & CSharpBinderFlags.CheckedContext) != 0)
                                expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null);
 
                        var restrictions = CSharpBinder.CreateRestrictionsOnTarget (target);
-                       return CSharpBinder.Bind (target, expr, restrictions, errorSuggestion);
+                       return CSharpBinder.Bind (this, expr, restrictions, errorSuggestion);
                }
        }
 }