Пример #1
0
        public bool Connect(IGeneratorDomain domain)
        {
            bool IsConnected = false;

            foreach (IGeneratorDynamicProperty DynamicProperty in Properties)
            {
                IsConnected |= DynamicProperty.Connect(domain);
            }

            return(IsConnected);
        }
Пример #2
0
        private void Generate(IGeneratorDomain domain, string appNamespace, StreamWriter cSharpWriter)
        {
            Dictionary <IGeneratorObject, List <IGeneratorObjectProperty> > UsedObjectTable = new Dictionary <IGeneratorObject, List <IGeneratorObjectProperty> >();

            foreach (IGeneratorDynamicProperty DynamicProperty in Properties)
            {
                DynamicProperty.GetUsedObjects(UsedObjectTable);
            }

            cSharpWriter.WriteLine("using System.ComponentModel;");
            cSharpWriter.WriteLine();
            cSharpWriter.WriteLine($"namespace {appNamespace}");
            cSharpWriter.WriteLine("{");
            cSharpWriter.WriteLine($"    public class {XamlPageName}Dynamic : INotifyPropertyChanged");
            cSharpWriter.WriteLine("    {");
            cSharpWriter.WriteLine($"        public {XamlPageName}Dynamic({XamlPageName} page)");
            cSharpWriter.WriteLine("        {");
            cSharpWriter.WriteLine("            Page = page;");

            foreach (KeyValuePair <IGeneratorObject, List <IGeneratorObjectProperty> > Entry in UsedObjectTable)
            {
                cSharpWriter.WriteLine($"            Page.Get{Entry.Key.CSharpName}.PropertyChanged += On{Entry.Key.CSharpName}PropertyChanged;");
            }

            cSharpWriter.WriteLine("        }");
            cSharpWriter.WriteLine();
            cSharpWriter.WriteLine($"        public {XamlPageName} Page {{ get; private set; }}");

            foreach (KeyValuePair <IGeneratorObject, List <IGeneratorObjectProperty> > Entry in UsedObjectTable)
            {
                string ObjectName = Entry.Key.CSharpName;

                cSharpWriter.WriteLine();
                cSharpWriter.WriteLine($"        public void On{ObjectName }PropertyChanged(object sender, PropertyChangedEventArgs e)");
                cSharpWriter.WriteLine("        {");
                cSharpWriter.WriteLine($"            OnPropertyChanged($\"{{nameof({ObjectName })}}.{{e.PropertyName}}\");");
                cSharpWriter.WriteLine("        }");
            }

            cSharpWriter.WriteLine();

            List <IGeneratorDynamicProperty> GeneratedProperties = new List <IGeneratorDynamicProperty>();

            foreach (KeyValuePair <IGeneratorObject, List <IGeneratorObjectProperty> > Entry in UsedObjectTable)
            {
                foreach (IGeneratorObjectProperty ObjectProperty in Entry.Value)
                {
                    foreach (IGeneratorDynamicProperty DynamicProperty in Properties)
                    {
                        if (!GeneratedProperties.Contains(DynamicProperty))
                        {
                            if (DynamicProperty.Generate(Entry.Key, ObjectProperty, cSharpWriter))
                            {
                                GeneratedProperties.Add(DynamicProperty);
                            }
                        }
                    }
                }
            }

            cSharpWriter.WriteLine();
            cSharpWriter.WriteLine($"        public void OnPropertyChanged(string propertyName)");
            cSharpWriter.WriteLine("        {");

            foreach (KeyValuePair <IGeneratorObject, List <IGeneratorObjectProperty> > Entry in UsedObjectTable)
            {
                string ObjectName = Entry.Key.CSharpName;

                foreach (IGeneratorObjectProperty ObjectProperty in Entry.Value)
                {
                    string ObjectPropertyName = ObjectProperty.CSharpName;

                    cSharpWriter.WriteLine($"            if (propertyName == $\"{{nameof({ObjectName})}}.{{nameof({ObjectName}.{ObjectPropertyName})}}\")");

                    foreach (IGeneratorDynamicProperty DynamicProperty in Properties)
                    {
                        DynamicProperty.GenerateNotification(Entry.Key, ObjectProperty, cSharpWriter);
                    }
                }
            }

            cSharpWriter.WriteLine("        }");
            cSharpWriter.WriteLine();
            cSharpWriter.WriteLine("        public event PropertyChangedEventHandler PropertyChanged;");
            cSharpWriter.WriteLine();
            cSharpWriter.WriteLine("        internal void NotifyPropertyChanged(string propertyName)");
            cSharpWriter.WriteLine("        {");
            cSharpWriter.WriteLine("            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));");
            cSharpWriter.WriteLine("        }");
            cSharpWriter.WriteLine("    }");
            cSharpWriter.WriteLine("}");
        }