示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleClass"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="namespace">The name space.</param>
 /// <param name="prefix">The prefix.</param>
 /// <param name="postfix">The postfix.</param>
 public SimpleClass(string name, AbstractNamespace @namespace, string prefix, string postfix)
 {
     this.name           = name;
     this.postfix        = postfix;
     this.prefix         = prefix;
     namespaceDefinition = @namespace;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleClass"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="namespace">The name space.</param>
 /// <param name="prefix">The prefix.</param>
 /// <param name="postfix">The postfix.</param>
 public SimpleClass(string name, AbstractNamespace @namespace, string prefix, string postfix)
 {
     this.name = name;
     this.postfix = postfix;
     this.prefix = prefix;
     namespaceDefinition = @namespace;
 }
示例#3
0
 /// <summary>
 /// Visits the specified name space.
 /// </summary>
 /// <param name="concreteNamespace">The name space.</param>
 public void Visit(AbstractNamespace concreteNamespace)
 {
     if (concreteNamespace == null)
     {
         throw new ArgumentNullException("concreteNamespace");
     }
     indent();
     writer.WriteLine("namespace {0}", concreteNamespace.Name);
 }
 /// <summary>
 /// Visits the specified name space.
 /// </summary>
 /// <param name="concreteNamespace">The name space.</param>
 public void Visit(AbstractNamespace concreteNamespace)
 {
     if (concreteNamespace == null)
         throw new ArgumentNullException("concreteNamespace");
     indent();
     writer.WriteLine("namespace {0}", concreteNamespace.Name);
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleClass"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="namespace">The name space.</param>
 /// <param name="prefix">The prefix.</param>
 public SimpleClass(string name, AbstractNamespace @namespace, string prefix)
     : this(name, @namespace, prefix, string.Empty)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DataTableClass"/> class.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        /// <param name="namespace">The @namespace.</param>
        /// <param name="prefix">The prefix.</param>
        public DataTableClass(DataTable dataTable, AbstractNamespace @namespace, string prefix)
        {
            if (string.IsNullOrEmpty(dataTable.TableName))
            {
                throw new ArgumentNullException("dataTable", "The data table must have a TableName.");
            }

            Name = TextUtilities.NormalizeForCode(dataTable.TableName, TextNormalizationType.Class);
            NamespaceDefinition = @namespace;
            Postfix             = "ISerializable";
            Prefix = "[Serializable]\n\t" + prefix;
            UsingClauses.Add(new SimpleUsingClause("System"));
            UsingClauses.Add(new SimpleUsingClause("System.Data"));
            UsingClauses.Add(new SimpleUsingClause("System.Runtime.Serialization"));
            UsingClauses.Add(new SimpleUsingClause("System.Security.Permissions"));

            // ISerializable pattern
            SimpleConstructor serializationConstructor = new SimpleConstructor(Name, "protected", null);

            serializationConstructor.Parameters.Add(new SimpleParameter("information", typeof(SerializationInfo), null));
            serializationConstructor.Parameters.Add(new SimpleParameter("context", typeof(StreamingContext), null));

            SimpleMethod serializationMethod = new SimpleMethod("GetObjectData",
                                                                "[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]\n\t\tpublic",
                                                                null);

            serializationMethod.Parameters.Add(new SimpleParameter("info", typeof(SerializationInfo), null));
            serializationMethod.Parameters.Add(new SimpleParameter("context", typeof(StreamingContext), null));

            // datarow constructor
            SimpleConstructor datarowConstructor = new SimpleConstructor(Name, "public", null);

            datarowConstructor.Parameters.Add(new SimpleParameter("dataRow", typeof(DataRow), null));

            foreach (DataColumn column in dataTable.Columns)
            {
                string fieldName = TextUtilities.NormalizeForCode(column.ColumnName, TextNormalizationType.Field);
                string typeName  = column.DataType.Name;

                Fields.Add(new SimpleField(fieldName, column.DataType, "private readonly"));

                SimpleGetter getter = new SimpleGetter();
                getter.Body.Add(string.Format(CultureInfo.InvariantCulture, "return {0};", fieldName));

                Properties.Add(new SimpleProperty(
                                   TextUtilities.NormalizeForCode(column.ColumnName, TextNormalizationType.Property), column.DataType,
                                   "public", getter, null));

                serializationConstructor.Body.Add(string.Format(CultureInfo.InvariantCulture,
                                                                "{0} = ({1}) information.GetValue(\"{0}\", typeof ({1}));",
                                                                fieldName, typeName));

                serializationMethod.Body.Add(string.Format(CultureInfo.InvariantCulture, "info.AddValue(\"{0}\", {1});", fieldName,
                                                           fieldName));

                datarowConstructor.Body.Add(string.Format(CultureInfo.InvariantCulture, "{0} = ({1})dataRow[\"{2}\"];", fieldName,
                                                          typeName, column.ColumnName));
            }

            Constructors.Add(serializationConstructor);
            Methods.Add(serializationMethod);

            Constructors.Add(datarowConstructor);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleClass"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="namespace">The name space.</param>
 /// <param name="prefix">The prefix.</param>
 public SimpleClass(string name, AbstractNamespace @namespace, string prefix)
     : this(name, @namespace, prefix, string.Empty)
 {
 }