示例#1
0
            internal ExtensionPropertyTracker AddPropertyInfo(string /*!*/ propName, MethodInfo get, MethodInfo set)
            {
                MethodInfo mi = get ?? set;

                List <ExtensionPropertyTracker> trackers;

                if (!_properties.TryGetValue(propName, out trackers))
                {
                    _properties[propName] = trackers = new List <ExtensionPropertyTracker>();
                }

                ExtensionPropertyTracker res;

                for (int i = 0; i < trackers.Count; i++)
                {
                    if (trackers[i].DeclaringType == mi.DeclaringType)
                    {
                        trackers[i] = res = new ExtensionPropertyTracker(
                            propName,
                            get ?? trackers[i].GetGetMethod(),
                            set ?? trackers[i].GetSetMethod(),
                            null,
                            mi.DeclaringType
                            );
                        return(res);
                    }
                }

                trackers.Add(
                    res = new ExtensionPropertyTracker(
                        propName,
                        get,
                        set,
                        null,
                        mi.DeclaringType
                        )
                    );

                return(res);
            }
示例#2
0
        internal static ReflectedGetterSetter GetReflectedProperty(PropertyTracker pt, MemberGroup allProperties, bool privateBinding)
        {
            ReflectedGetterSetter rp;

            lock (_propertyCache) {
                if (_propertyCache.TryGetValue(pt, out rp))
                {
                    return(rp);
                }

                NameType   nt     = NameType.PythonProperty;
                MethodInfo getter = FilterProtectedGetterOrSetter(pt.GetGetMethod(true), privateBinding);
                MethodInfo setter = FilterProtectedGetterOrSetter(pt.GetSetMethod(true), privateBinding);

                if ((getter != null && PythonHiddenAttribute.IsHidden(getter, true)) ||
                    (setter != null && PythonHiddenAttribute.IsHidden(setter, true)))
                {
                    nt = NameType.Property;
                }

                ExtensionPropertyTracker ept = pt as ExtensionPropertyTracker;
                if (ept == null)
                {
                    ReflectedPropertyTracker rpt = pt as ReflectedPropertyTracker;
                    Debug.Assert(rpt != null);

                    if (PythonBinder.IsExtendedType(pt.DeclaringType) ||
                        PythonHiddenAttribute.IsHidden(rpt.Property, true))
                    {
                        nt = NameType.Property;
                    }

                    if (pt.GetIndexParameters().Length == 0)
                    {
                        List <MethodInfo> getters = new List <MethodInfo>();
                        List <MethodInfo> setters = new List <MethodInfo>();

                        IList <ExtensionPropertyTracker> overriddenProperties = NewTypeMaker.GetOverriddenProperties((getter ?? setter).DeclaringType, pt.Name);
                        foreach (ExtensionPropertyTracker tracker in overriddenProperties)
                        {
                            MethodInfo method = tracker.GetGetMethod(privateBinding);
                            if (method != null)
                            {
                                getters.Add(method);
                            }

                            method = tracker.GetSetMethod(privateBinding);
                            if (method != null)
                            {
                                setters.Add(method);
                            }
                        }

                        foreach (PropertyTracker propTracker in allProperties)
                        {
                            MethodInfo method = propTracker.GetGetMethod(privateBinding);
                            if (method != null)
                            {
                                getters.Add(method);
                            }

                            method = propTracker.GetSetMethod(privateBinding);
                            if (method != null)
                            {
                                setters.Add(method);
                            }
                        }
                        rp = new ReflectedProperty(rpt.Property, getters.ToArray(), setters.ToArray(), nt);
                    }
                    else
                    {
                        rp = new ReflectedIndexer(((ReflectedPropertyTracker)pt).Property, NameType.Property, privateBinding);
                    }
                }
                else
                {
                    rp = new ReflectedExtensionProperty(new ExtensionPropertyInfo(pt.DeclaringType, getter ?? setter), nt);
                }

                _propertyCache[pt] = rp;

                return(rp);
            }
        }