コード例 #1
0
 /// <summary>
 /// Create the template output
 /// </summary>
 public virtual string TransformText()
 {
     foreach (var namespaceGroup in g.Types.GroupBy(x => x.Namespace).OrderBy(x => x.Key))
     {
         this.Write("namespace ");
         this.Write(this.ToStringHelper.ToStringWithCulture(namespaceGroup.Key));
         this.Write("\r\n{\r\n");
         foreach (var type in namespaceGroup.OrderBy(x => x.Name))
         {
             this.Write("    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"");
             this.Write(this.ToStringHelper.ToStringWithCulture(g.GeneratorName));
             this.Write("\", \"");
             this.Write(this.ToStringHelper.ToStringWithCulture(g.GeneratorVersion));
             this.Write("\")]\r\n    class ");
             this.Write(this.ToStringHelper.ToStringWithCulture(type.Name));
             this.Write("Writer : Nine.Serialization.IBinaryObjectWriter\r\n    {\r\n        public System.Typ" +
                        "e ReaderType { get { return typeof(");
             this.Write(this.ToStringHelper.ToStringWithCulture(type.Namespace));
             this.Write(".");
             this.Write(this.ToStringHelper.ToStringWithCulture(type.Name));
             this.Write("Reader); } }\r\n        public System.Type TargetType { get { return typeof(");
             this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
             this.Write("); } }\r\n                \r\n        public void Write(System.IO.BinaryWriter output" +
                        ", object obj, System.IServiceProvider serviceProvider)\r\n        {\r\n            v" +
                        "ar value = (");
             this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
             this.Write(")obj;\r\n");
             foreach (var property in type.Properties)
             {
                 WriteLine(property.Type.ToWriteString("output", "value." + property.Name, 0));
             }
             this.Write("        }\r\n    }\r\n");
         }
         this.Write("}\r\n");
     }
     return(this.GenerationEnvironment.ToString());
 }
コード例 #2
0
 /// <summary>
 /// Create the template output
 /// </summary>
 public virtual string TransformText()
 {
     foreach (var namespaceGroup in g.Types.GroupBy(x => x.Namespace).OrderBy(x => x.Key))
     {
         this.Write("namespace ");
         this.Write(this.ToStringHelper.ToStringWithCulture(namespaceGroup.Key));
         this.Write("\r\n{\r\n");
         foreach (var type in namespaceGroup.OrderBy(x => x.Name))
         {
             this.Write("    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"");
             this.Write(this.ToStringHelper.ToStringWithCulture(g.GeneratorName));
             this.Write("\", \"");
             this.Write(this.ToStringHelper.ToStringWithCulture(g.GeneratorVersion));
             this.Write("\")]\r\n    class ");
             this.Write(this.ToStringHelper.ToStringWithCulture(type.Name));
             this.Write("Reader : Nine.Serialization.IBinaryObjectReader\r\n    {\r\n        public object Rea" +
                        "d(System.IO.BinaryReader input, object existingInstance, System.IServiceProvider" +
                        " serviceProvider)\r\n        {\r\n            var result = existingInstance as ");
             this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
             this.Write(";\r\n            if (result == null)\r\n            {\r\n");
             if (type.ConstructorParameters != null)
             {
                 this.Write("                result = new ");
                 this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
                 this.Write("(\r\n");
                 for (var i = 0; i < type.ConstructorParameters.Length; i++)
                 {
                     if (i != 0)
                     {
                         this.Write(",");
                     }
                     this.Write(" ");
                     this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.ConstructorParameters[i].DeclaringType)));
                     this.Write(".");
                     this.Write(this.ToStringHelper.ToStringWithCulture(type.ConstructorParameters[i].Name));
                     this.Write("(serviceProvider)\r\n");
                 }
                 this.Write(");\r\n");
             }
             else if (type.HasServiceProviderConstructor)
             {
                 this.Write("                result = new ");
                 this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
                 this.Write("(serviceProvider);\r\n");
             }
             else
             {
                 this.Write("                result = new ");
                 this.Write(this.ToStringHelper.ToStringWithCulture(PropertyTypeData.GetClassFullName(type.Type)));
                 this.Write("();\r\n");
             }
             this.Write("            }\r\n");
             if (type.SupportsInitialize)
             {
                 this.Write("            ((System.ComponentModel.ISupportInitialize)result).BeginInit();\r\n");
             }
             foreach (var property in type.Properties)
             {
                 WriteLine(property.Type.ToReadString("input", "result." + property.Name, 0));
             }
             if (type.SupportsInitialize)
             {
                 this.Write("            ((System.ComponentModel.ISupportInitialize)result).EndInit();\r\n");
             }
             this.Write("            return result;\r\n        }\r\n    }\r\n");
         }
         this.Write("}\r\n");
     }
     return(this.GenerationEnvironment.ToString());
 }