Exemplo n.º 1
0
        internal DynamicMetaObjectBinder ConvertRetObject(Type type, ConversionResultKind resultKind)
        {
            if (_convertRetObjectBinders == null)
            {
                Interlocked.CompareExchange(
                    ref _convertRetObjectBinders,
                    new Dictionary<Type, DynamicMetaObjectBinder>[(int)ConversionResultKind.ImplicitTry + 1],
                    null
                );
            }

            if (_convertRetObjectBinders[(int)resultKind] == null)
            {
                Interlocked.CompareExchange(
                    ref _convertRetObjectBinders[(int)resultKind],
                    new Dictionary<Type, DynamicMetaObjectBinder>(),
                    null
                );
            }

            Dictionary<Type, DynamicMetaObjectBinder> dict = _convertRetObjectBinders[(int)resultKind];
            lock (dict)
            {
                DynamicMetaObjectBinder res;
                if (!dict.TryGetValue(type, out res))
                    dict[type] = res = new TotemConversionBinder(this, type, resultKind, true);

                return res;
            }
        }
Exemplo n.º 2
0
 public DynamicConvertExpression(TotemConversionBinder binder, CompilationMode mode, Expression target)
 {
     _binder = binder;
     _mode = mode;
     _target = target;
 }
Exemplo n.º 3
0
        internal TotemConversionBinder Convert(Type type, ConversionResultKind resultKind)
        {
            if (_conversionBinders == null)
            {
                Interlocked.CompareExchange(
                    ref _conversionBinders,
                    new Dictionary<Type, TotemConversionBinder>[(int)ConversionResultKind.ExplicitTry + 1], // max conversion result kind
                    null
                );
            }

            if (_conversionBinders[(int)resultKind] == null)
            {
                Interlocked.CompareExchange(
                    ref _conversionBinders[(int)resultKind],
                    new Dictionary<Type, TotemConversionBinder>(),
                    null
                );
            }

            Dictionary<Type, TotemConversionBinder> dict = _conversionBinders[(int)resultKind];
            lock (dict)
            {
                TotemConversionBinder res;
                if (!dict.TryGetValue(type, out res))
                    dict[type] = res = new TotemConversionBinder(this, type, resultKind);

                return res;
            }
        }