示例#1
0
        internal static bool WireUpForInterface(this ShapeableObject bindSite, string binderName, bool found,
                                                ref object itf)
        {
            if (itf is InterceptorAddRemove)
            {
                return(true);
            }

            Type theType;
            bool gotType = bindSite.GetTypeForPropertyNameFromInterface(binderName, out theType);

            if (gotType && theType == typeof(void))
            {
                return(true);
            }

            if (found)
            {
                itf = WireUpForInterfaceUsingType(gotType, theType, bindSite, itf);
            }
            else
            {
                itf = null;
                if (!gotType)
                {
                    return(false);
                }

                if (theType.IsValueType)
                {
                    itf = InvocationBinding.CreateInstance(theType);
                }
            }

            return(true);
        }
示例#2
0
        private static object WireUpForInterfaceUsingType(bool gotType, Type theType, ShapeableObject bindSite,
                                                          object itf)
        {
            if (IsDictionaryButNotExpando(itf, gotType, theType))
            {
                itf = new ShapeableExpando((IDictionary <string, object>)itf);
            }
            else if (gotType)
            {
                if (itf != null && !theType.IsAssignableFrom(itf.GetType()))
                {
                    if (theType.IsInterface)
                    {
                        itf = InterfaceProjection(theType, itf);
                    }
                    else
                    {
                        try
                        {
                            object tResult;

                            tResult = InvocationBinding.Conversion(bindSite, theType, explict: true);

                            itf = tResult;
                        }
                        catch (RuntimeBinderException)
                        {
                            itf = MaybeConvert(theType, itf);
                        }
                    }
                }
                else if (null == itf && theType.IsValueType)
                {
                    itf = InvocationBinding.CreateInstance(theType);
                }
            }

            return(itf);
        }