private CompositeClass ReadSourceFile()
        {
            CompositeClass compositeClass = new CompositeClass();
            compositeClass.Namespaces.Add("System");

            XmlDocument document = new XmlDocument();
            document.Load(_inputFileName);

            XmlNode compositeNode = document.SelectSingleNode(CompositeXPath);
            compositeClass.RootNamespace = GetNodeValue(compositeNode, "@rootNamespace");

            XmlNodeList types = document.SelectNodes(TypesXPath);
            foreach (XmlNode typeNode in types)
            {
                string name = GetNodeValue(typeNode, "@name");
                string className = GetNodeValue(typeNode, "@className");
                string theNamespace = GetNodeValue(typeNode, "@namespace");
                if (!compositeClass.Namespaces.Contains(theNamespace))
                {
                    compositeClass.Namespaces.Add(theNamespace);
                }

                CompositeType compositeType = new CompositeType(name, className, theNamespace);
                compositeClass.Types.Add(compositeType);
                Type actualType = FindType(className, theNamespace);

                foreach (PropertyInfo pi in actualType.GetProperties())
                {
                    if (pi.CanRead && pi.CanWrite)
                    {
                        CompositeProperty property = new CompositeProperty(compositeType.TypeName, pi.Name, pi.PropertyType);
                        compositeType.Properties.Add(property);
                    }
                }

                XmlNodeList hiddenNodes = typeNode.SelectNodes(PropertiesXPath);
                foreach (XmlNode propertyNode in hiddenNodes)
                {
                    string propertyName = GetNodeValue(propertyNode, "@name");
                    string alias = GetNodeValue(propertyNode, "@alias");
                    bool isReadOnly = GetBooleanNodeValue(propertyNode, "@isReadOnly");
                    bool isHidden = GetBooleanNodeValue(propertyNode, "@isHidden");

                    CompositeProperty property = compositeType.Properties.FindCompositeProperty(name, propertyName);

                    if (property != null)
                    {
                        if (!String.IsNullOrEmpty(alias))
                        {
                            property.Alias = alias;
                        }
                        property.IsReadOnly = isReadOnly;
                        property.IsHidden = isHidden;
                    }
                }
            }

            return compositeClass;
        }
        public CodeCompileUnit CreateCodeCompileUnit(CompositeClass compositeClass)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            CodeNamespace ns = new CodeNamespace(GetNamespace(compositeClass.RootNamespace));
            foreach (string newNamespace in compositeClass.Namespaces)
            {
                CodeNamespaceImport import = new CodeNamespaceImport(newNamespace);
                ns.Imports.Add(import);
            }
            unit.Namespaces.Add(ns);

            CodeTypeDeclaration generatedClass = new CodeTypeDeclaration(GetClassName());
            generatedClass.IsClass = true;
            generatedClass.IsPartial = true;
            generatedClass.TypeAttributes = TypeAttributes.Public;
            ns.Types.Add(generatedClass);

            // add private fields
            foreach (CompositeType compositeType in compositeClass.Types)
            {
                CodeMemberField privateVariable = new CodeMemberField(compositeType.ClassName, compositeType.GetFieldName());
                privateVariable.Attributes = MemberAttributes.Private;
                generatedClass.Members.Add(privateVariable);
            }

            // add constructor
            CodeConstructor ctor = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;

            // add the parameters and field assignments
            foreach (CompositeType compositeType in compositeClass.Types)
            {
                CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(
                    compositeType.ClassName, compositeType.GetParameterName());
                ctor.Parameters.Add(param);

                // add field assignment
                CodeFieldReferenceExpression leftRef;
                leftRef = new CodeFieldReferenceExpression();
                //leftRef.TargetObject = new CodeThisReferenceExpression();
                leftRef.FieldName = compositeType.GetFieldName();

                CodeFieldReferenceExpression rightRef;
                rightRef = new CodeFieldReferenceExpression();
                //rightRef.TargetObject = new CodeThisReferenceExpression();
                rightRef.FieldName = compositeType.GetParameterName();

                CodeAssignStatement assign = new CodeAssignStatement();
                assign.Left = leftRef;
                assign.Right = rightRef;

                ctor.Statements.Add(assign);
            }
            generatedClass.Members.Add(ctor);

            // add properties
            foreach (CompositeType compositeType in compositeClass.Types)
            {
                foreach (CompositeProperty property in compositeType.Properties)
                {
                    AttachProperty(generatedClass, compositeType, property);
                }
            }

            return unit;
        }
 public void LoadFile(string filename)
 {
     _compositeClass = new CompositeClass();
     _compositeClass.LoadFile(filename);
 }