Пример #1
0
        internal DynamicMetaObjectBinder ConvertAndReturnObject(Type type, ConversionResultKind resultKind)
        {
            if (_convertRetObjectBinders == null)
            {
                Interlocked.CompareExchange(
                    ref _convertRetObjectBinders,
                    new Dictionary <Type, DynamicMetaObjectBinder> [(int)ConversionResultKind.ExplicitTry + 1], // max conversion result kind
                    null);
            }

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

            var binder = _convertRetObjectBinders[(int)resultKind];

            lock (binder)
            {
                DynamicMetaObjectBinder result;
                if (!binder.TryGetValue(type, out result))
                {
                    binder[type] = result = new SxeConvertBinder(this, type, resultKind, _binder.Context.OverloadResolver);
                }

                return(result);
            }
        }
Пример #2
0
        internal SxeConvertBinder Convert(Type type, ConversionResultKind resultKind, OverloadResolverFactory resolverFactory)
        {
            if (_conversionBinders == null)
            {
                Interlocked.CompareExchange(
                    ref _conversionBinders,
                    new Dictionary <Type, SxeConvertBinder> [(int)ConversionResultKind.ExplicitTry + 1], // max conversion result kind
                    null
                    );
            }

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

            var binders = _conversionBinders[(int)resultKind];

            lock (binders)
            {
                SxeConvertBinder result;
                if (!binders.TryGetValue(type, out result))
                {
                    binders[type] = result = new SxeConvertBinder(this, type, resultKind, resolverFactory);
                }
                return(result);
            }
        }