Пример #1
0
        public virtual MemberPropertyDefinition[] GetProperties()
        {
            if (_properties != null)
            {
                return(_properties);
            }

            _properties = MemberPropertyDefinition.GetPropertiesFromMethods(this.Methods);

            if (GetInterfaces().Length > 0)
            {
                foreach (MemberPropertyDefinition prop in _properties)
                {
                    if (!prop.CanWrite)
                    {
                        foreach (ClassDefinition iface in GetInterfaces())
                        {
                            MemberPropertyDefinition ip = iface.GetProperty(prop.Name, true);
                            if (ip != null && ip.CanWrite)
                            {
                                prop.SetterFunction = ip.SetterFunction;
                                break;
                            }
                        }
                    }

                    if (!prop.CanRead)
                    {
                        foreach (ClassDefinition iface in GetInterfaces())
                        {
                            MemberPropertyDefinition ip = iface.GetProperty(prop.Name, true);
                            if (ip != null && ip.CanRead)
                            {
                                prop.GetterFunction = ip.GetterFunction;
                                break;
                            }
                        }
                    }
                }
            }

            return(_properties);
        }
Пример #2
0
        protected virtual void Init()
        {
            if (_initCalled)
            {
                return;
            }

            _initCalled = true;

            foreach (MemberMethodDefinition f in _classDefinition.PublicMethods)
            {
                if (f.IsListenerAdder && !f.IsIgnored)
                {
                    _listeners.Add((ClassDefinition)f.Parameters[0].Type);
                }
            }

            foreach (ClassDefinition iface in _classDefinition.GetInterfaces())
            {
                // Add attributes of interface methods from the interface classes
                foreach (MemberMethodDefinition f in iface.Methods)
                {
                    MemberMethodDefinition tf = _classDefinition.GetMethodWithSignature(f.Signature);
                    if (tf != null)
                    {
                        tf.AddAttributes(f.Attributes);
                    }
                }

                //Store properties of interface classes. They have precedence over type's properties.
                foreach (MemberPropertyDefinition ip in iface.GetProperties())
                {
                    if (IsPropertyAllowed(ip) &&
                        (ip.ProtectionLevel == ProtectionLevel.Public ||
                         (AllowProtectedMembers && ip.ProtectionLevel == ProtectionLevel.Protected)))
                    {
                        _interfaceProperties.Add(ip);
                    }
                }
            }

            foreach (MemberFieldDefinition field in _classDefinition.Fields)
            {
                if (!field.IsIgnored && field.MemberType.IsSTLContainer)
                {
                    if (field.ProtectionLevel == ProtectionLevel.Public ||
                        ((AllowSubclassing || AllowProtectedMembers) && field.ProtectionLevel == ProtectionLevel.Protected))
                    {
                        MarkCachedMember(field);
                    }
                }
            }

            foreach (ClassDefinition iface in _interfaces)
            {
                if (iface == _classDefinition)
                {
                    continue;
                }

                foreach (MemberFieldDefinition field in iface.Fields)
                {
                    if (!field.IsIgnored && field.MemberType.IsSTLContainer &&
                        !field.IsStatic)
                    {
                        if (field.ProtectionLevel == ProtectionLevel.Public ||
                            ((AllowSubclassing || AllowProtectedMembers) && field.ProtectionLevel == ProtectionLevel.Protected))
                        {
                            MarkCachedMember(field);
                        }
                    }
                }
            }

            foreach (MemberMethodDefinition func in _classDefinition.AbstractFunctions)
            {
                if (func.ProtectionLevel == ProtectionLevel.Public ||
                    (AllowProtectedMembers && func.ProtectionLevel == ProtectionLevel.Protected))
                {
                    if ((func.ContainingClass.AllowSubClassing || (func.ContainingClass == _classDefinition && AllowSubclassing)) && !func.IsProperty)
                    {
                        _isAbstractClass = true;
                        _abstractFunctions.Add(func);
                    }
                }
            }

            foreach (MemberPropertyDefinition prop in _classDefinition.AbstractProperties)
            {
                if (IsPropertyAllowed(prop) && (prop.ContainingClass.AllowSubClassing ||
                                                (prop.ContainingClass == _classDefinition && AllowSubclassing)))
                {
                    if (prop.ProtectionLevel == ProtectionLevel.Public ||
                        (AllowProtectedMembers && prop.ProtectionLevel == ProtectionLevel.Protected))
                    {
                        _isAbstractClass = true;
                        _abstractProperties.Add(prop);
                    }
                }
            }

            SearchOverridableFunctions(_classDefinition);
            //SearchProtectedFields(_t);

            foreach (ClassDefinition iface in _interfaces)
            {
                SearchOverridableFunctions(iface);
                //SearchProtectedFields(iface);
            }

            _overridableProperties = MemberPropertyDefinition.GetPropertiesFromMethods(_overridableFunctions);

            //Find cached members

            foreach (MemberDefinitionBase m in _classDefinition.Members)
            {
                if (m.HasAttribute <CachedGetAccessorAttribute>())
                {
                    MarkCachedMember(m);
                }
            }

            foreach (ClassDefinition iface in _interfaces)
            {
                if (iface == _classDefinition)
                {
                    continue;
                }

                foreach (MemberDefinitionBase m in iface.Members)
                {
                    if (m.HasAttribute <CachedGetAccessorAttribute>())
                    {
                        MarkCachedMember(m);
                    }
                }
            }
        }