예제 #1
0
        private void CreateCachedProperties()
        {
            // Check if any property values can be cached in
            // in constructors or property setters
            foreach (var @class in Classes.Values)
            {
                foreach (var constructor in @class.Methods.Where(m => m.Native.IsConstructor))
                {
                    foreach (var param in constructor.Parameters)
                    {
                        var methodParent = constructor.Parent;
                        while (methodParent != null)
                        {
                            foreach (var property in methodParent.Properties)
                            {
                                if (param.Name.ToLower() == property.Name.ToLower() &&
                                    IsCacheableType(param.Native.Type) &&
                                    GetName(param.Native.Type).Equals(GetName(property.Type)))
                                {
                                    CachedProperty cachedProperty;
                                    if (methodParent.CachedProperties.TryGetValue(property.Name, out cachedProperty))
                                    {
                                        if (methodParent != constructor.Parent)
                                        {
                                            cachedProperty.Access = RefAccessSpecifier.Protected;
                                        }
                                    }
                                    else
                                    {
                                        cachedProperty = new CachedProperty(property);
                                        methodParent.CachedProperties.Add(property.Name, cachedProperty);
                                    }
                                }
                            }
                            methodParent = methodParent.BaseClass;
                        }
                    }
                }

                foreach (var property in @class.Properties.Where(p => p.Setter != null))
                {
                    if (IsCacheableType(property.Type))
                    {
                        if ([email protected](property.Name))
                        {
                            @class.CachedProperties.Add(property.Name, new CachedProperty(property));
                        }
                    }
                }
            }
        }
        public override void Parse()
        {
            base.Parse();

            // Check if any property values can be cached in
            // in constructors or property setters
            foreach (var @class in classDefinitions.Values)
            {
                foreach (var constructor in @class.Methods.Where(m => m.IsConstructor))
                {
                    foreach (var param in constructor.Parameters)
                    {
                        var methodParent = constructor.Parent;
                        while (methodParent != null)
                        {
                            foreach (var property in methodParent.Properties)
                            {
                                if (param.ManagedName.ToLower() == property.Name.ToLower()
                                    && IsCacheableType(param.Type)
                                    && param.Type.ManagedName == property.Type.ManagedName)
                                {
                                    CachedProperty cachedProperty;
                                    if (methodParent.CachedProperties.TryGetValue(property.Name, out cachedProperty))
                                    {
                                        if (methodParent != constructor.Parent)
                                        {
                                            cachedProperty.Access = RefAccessSpecifier.Protected;
                                        }
                                    }
                                    else
                                    {
                                        cachedProperty = new CachedProperty(property);
                                        methodParent.CachedProperties.Add(property.Name, cachedProperty);
                                    }
                                }
                            }
                            methodParent = methodParent.BaseClass;
                        }
                    }
                }

                foreach (var property in @class.Properties.Where(p => p.Setter != null))
                {
                    if (IsCacheableType(property.Type))
                    {
                        if ([email protected](property.Name))
                        {
                            @class.CachedProperties.Add(property.Name, new CachedProperty(property));
                        }
                    }
                }
            }

            // Sort methods and properties alphabetically
            foreach (var @class in classDefinitions.Values)
            {
                // Order by name, then fix inheritance, parent classes must appear first
                @class.Classes.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
                var classesOrdered = @class.Classes;
                for (int i = 0; i < classesOrdered.Count; i++)
                {
                    var thisClass = classesOrdered[i];
                    var baseClass = thisClass.BaseClass;
                    if (baseClass != null && classesOrdered.Contains(baseClass))
                    {
                        int thisIndex = classesOrdered.IndexOf(thisClass);
                        if (thisIndex < classesOrdered.IndexOf(baseClass))
                        {
                            classesOrdered.Remove(baseClass);
                            classesOrdered.Insert(thisIndex, baseClass);
                        }
                    }
                }

                @class.Methods.Sort((m1, m2) => m1.Name.CompareTo(m2.Name));
                @class.Properties.Sort((p1, p2) => p1.Name.CompareTo(p2.Name));
            }
        }
예제 #3
0
        public override void Parse()
        {
            base.Parse();

            // Check if any property values can be cached in
            // in constructors or property setters
            foreach (var @class in classDefinitions.Values)
            {
                foreach (var constructor in @class.Methods.Where(m => m.IsConstructor))
                {
                    foreach (var param in constructor.Parameters)
                    {
                        var methodParent = constructor.Parent;
                        while (methodParent != null)
                        {
                            foreach (var property in methodParent.Properties)
                            {
                                if (param.ManagedName.ToLower() == property.Name.ToLower() &&
                                    IsCacheableType(param.Type) &&
                                    param.Type.ManagedName == property.Type.ManagedName)
                                {
                                    CachedProperty cachedProperty;
                                    if (methodParent.CachedProperties.TryGetValue(property.Name, out cachedProperty))
                                    {
                                        if (methodParent != constructor.Parent)
                                        {
                                            cachedProperty.Access = RefAccessSpecifier.Protected;
                                        }
                                    }
                                    else
                                    {
                                        cachedProperty = new CachedProperty(property);
                                        methodParent.CachedProperties.Add(property.Name, cachedProperty);
                                    }
                                }
                            }
                            methodParent = methodParent.BaseClass;
                        }
                    }
                }

                foreach (var property in @class.Properties.Where(p => p.Setter != null))
                {
                    if (IsCacheableType(property.Type))
                    {
                        if ([email protected](property.Name))
                        {
                            @class.CachedProperties.Add(property.Name, new CachedProperty(property));
                        }
                    }
                }
            }

            // Sort methods and properties alphabetically
            foreach (var @class in classDefinitions.Values)
            {
                // Order by name, then fix inheritance, parent classes must appear first
                @class.Classes.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
                var classesOrdered = @class.Classes;
                for (int i = 0; i < classesOrdered.Count; i++)
                {
                    var thisClass = classesOrdered[i];
                    var baseClass = thisClass.BaseClass;
                    if (baseClass != null && classesOrdered.Contains(baseClass))
                    {
                        int thisIndex = classesOrdered.IndexOf(thisClass);
                        if (thisIndex < classesOrdered.IndexOf(baseClass))
                        {
                            classesOrdered.Remove(baseClass);
                            classesOrdered.Insert(thisIndex, baseClass);
                        }
                    }
                }

                @class.Methods.Sort((m1, m2) => m1.Name.CompareTo(m2.Name));
                @class.Properties.Sort((p1, p2) => p1.Name.CompareTo(p2.Name));
            }
        }
        private void CreateCachedProperties()
        {
            // Check if any property values can be cached in
            // in constructors or property setters
            foreach (var @class in Classes.Values)
            {
                foreach (var constructor in @class.Methods.Where(m => m.Native.IsConstructor))
                {
                    foreach (var param in constructor.Parameters)
                    {
                        var methodParent = constructor.Parent;
                        while (methodParent != null)
                        {
                            foreach (var property in methodParent.Properties)
                            {
                                if (param.Name.ToLower() == property.Name.ToLower()
                                    && IsCacheableType(param.Native.Type)
                                    && GetName(param.Native.Type).Equals(GetName(property.Type)))
                                {
                                    CachedProperty cachedProperty;
                                    if (methodParent.CachedProperties.TryGetValue(property.Name, out cachedProperty))
                                    {
                                        if (methodParent != constructor.Parent)
                                        {
                                            cachedProperty.Access = RefAccessSpecifier.Protected;
                                        }
                                    }
                                    else
                                    {
                                        cachedProperty = new CachedProperty(property);
                                        methodParent.CachedProperties.Add(property.Name, cachedProperty);
                                    }
                                }
                            }
                            methodParent = methodParent.BaseClass;
                        }
                    }
                }

                foreach (var property in @class.Properties.Where(p => p.Setter != null))
                {
                    if (IsCacheableType(property.Type))
                    {
                        if ([email protected](property.Name))
                        {
                            @class.CachedProperties.Add(property.Name, new CachedProperty(property));
                        }
                    }
                }
            }
        }