10 namespace SiliconStudio.AssemblyProcessor
14 using System.Reflection;
15 using System.Collections.Generic;
17 using SiliconStudio.Core.Serialization.Serializers;
24 #line 1 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
25 [global::System.CodeDom.Compiler.GeneratedCodeAttribute(
"Microsoft.VisualStudio.TextTemplating",
"12.0.0.0")]
26 internal partial
class ComplexSerializerCodeGenerator : ComplexSerializerCodeGeneratorBase
32 public virtual string TransformText()
36 using System.Collections.Generic;
37 using System.Reflection;
38 using SiliconStudio.Core.Serialization;
39 using SiliconStudio.Core.Reflection;
40 using SiliconStudio.Core.Serialization.Serializers;
41 using SiliconStudio.DataSerializers;
43 [assembly: AssemblyVersion(""");
45 #line 17 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
46 this.Write(this.ToStringHelper.ToStringWithCulture(assembly.Name.Version.ToString()));
50 this.Write(
"\")]\r\n");
52 #line 18 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
53 if (targetFramework != null) {
57 this.Write(
"[assembly: System.Runtime.Versioning.TargetFramework(");
59 #line 19 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
60 this.Write(this.ToStringHelper.ToStringWithCulture(targetFramework));
66 #line 20 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
71 this.Write(
"\r\n[assembly: SiliconStudio.Core.Serialization.Serializers.AssemblySerializerFacto" +
72 "ry(Type = typeof(SiliconStudio.DataSerializers.");
74 #line 22 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
75 this.Write(this.ToStringHelper.ToStringWithCulture(assemblySerializerFactoryClassName));
81 namespace SiliconStudio.Core.Serialization.Serializers
83 class AssemblySerializerFactoryAttribute : Attribute
89 namespace SiliconStudio.DataSerializers
91 // Assembly attributes that defines supported serializer (only generics one so that other assemblies can do generic instantiations by themselves)
94 #line 35 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
95 foreach (var profile
in cecilSerializerContext.SerializableTypesProfiles) {
96 foreach (var type
in profile.Value.SerializableTypes.Where(x => x.Value.Local && x.Value.SerializerType != null)) {
100 this.Write(
" [DataSerializerGlobalAttribute(typeof(");
102 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
103 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.SerializerType.ConvertCSharp(
false)));
107 this.Write(
"), typeof(");
109 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
110 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertCSharp(
false)));
114 this.Write(
"), DataSerializerGenericMode.");
116 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
117 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.Mode.ToString()));
123 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
124 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.Inherited ?
"true" :
"false"));
130 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
131 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.ComplexSerializer ?
"true" :
"false"));
135 this.Write(
", Profile = \"");
137 #line 37 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
138 this.Write(this.ToStringHelper.ToStringWithCulture(profile.Key));
142 this.Write(
"\")]\r\n");
144 #line 38 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
146 foreach (var type
in profile.Value.GenericSerializableTypes.Where(x => x.Value.Local && x.Value.SerializerType != null)) {
150 this.Write(
" [DataSerializerGlobalAttribute(typeof(");
152 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
153 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.SerializerType.ConvertCSharp(
true)));
157 this.Write(
"), typeof(");
159 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
160 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertCSharp(
true)));
164 this.Write(
"), DataSerializerGenericMode.");
166 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
167 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.Mode.ToString()));
173 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
174 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.Inherited ?
"true" :
"false"));
180 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
181 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.ComplexSerializer ?
"true" :
"false"));
185 this.Write(
", Profile = \"");
187 #line 40 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
188 this.Write(this.ToStringHelper.ToStringWithCulture(profile.Key));
192 this.Write(
"\")]\r\n");
194 #line 41 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
200 this.Write(
" \tpublic static class ");
202 #line 43 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
203 this.Write(this.ToStringHelper.ToStringWithCulture(assemblySerializerFactoryClassName));
207 this.Write(
"\r\n\t{\r\n\t [SiliconStudio.Core.ModuleInitializer]\r\n internal static void I" +
208 "nitialize()\r\n {\r\n");
210 #line 48 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
211 foreach (var profile
in cecilSerializerContext.SerializableTypesProfiles) {
215 this.Write(
"\t\t\tDataSerializerFactory.RegisterSerializationProfile(\"");
217 #line 49 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
218 this.Write(this.ToStringHelper.ToStringWithCulture(profile.Key));
222 this.Write(
"\", Register");
224 #line 49 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
225 this.Write(this.ToStringHelper.ToStringWithCulture(profile.Key));
229 this.Write(
");\r\n");
231 #line 50 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
236 this.Write(
" }\r\n\r\n");
238 #line 53 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
239 foreach (var profile
in cecilSerializerContext.SerializableTypesProfiles) {
243 this.Write(
"\t\tpublic static void Register");
245 #line 54 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
246 this.Write(this.ToStringHelper.ToStringWithCulture(profile.Key));
250 this.Write(
"(DataSerializerFactory serializerFactory)\r\n\t\t{\r\n\t\t\t// Force module .ctor of refer" +
251 "enced assemblies to be initialized as well\r\n");
253 #line 57 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
254 foreach (var referencedAssemblySerializerFactoryType
in referencedAssemblySerializerFactoryTypes) {
258 this.Write(
"\t\t\tModuleRuntimeHelpers.RunModuleConstructor(typeof(");
260 #line 58 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
261 this.Write(this.ToStringHelper.ToStringWithCulture(referencedAssemblySerializerFactoryType.ConvertCSharp()));
265 this.Write(
").GetTypeInfo().Module);\r\n");
267 #line 59 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
272 this.Write(
"\r\n\t\t\t// Register types used by this assembly\r\n");
274 #line 62 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
275 foreach (var type
in profile.Value.SerializableTypes.Where(x => x.Value.Local)) {
279 this.Write(
"\t\t\tif (!serializerFactory.CanSerialize(typeof(");
281 #line 63 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
282 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertCSharp()));
286 this.Write(
")))\r\n\t\t\t{\r\n");
288 #line 65 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
289 if (type.Value.SerializerType != null) {
293 this.Write(
"\t\t\t\tserializerFactory.RegisterSerializer(");
295 #line 66 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
296 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertTypeId()));
300 this.Write(
", new ");
302 #line 66 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
303 this.Write(this.ToStringHelper.ToStringWithCulture(type.Value.SerializerType.ConvertCSharp()));
307 this.Write(
"());\r\n");
309 #line 67 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
314 this.Write(
"\t\t\t\tserializerFactory.RegisterNullSerializer(");
316 #line 68 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
317 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertTypeId()));
321 this.Write(
", typeof(");
323 #line 68 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
324 this.Write(this.ToStringHelper.ToStringWithCulture(type.Key.ConvertCSharp()));
328 this.Write(
"));\r\n");
330 #line 69 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
335 this.Write(
"\t\t\t}\r\n");
337 #line 71 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
342 this.Write(
"\t\t}\r\n\r\n");
344 #line 74 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
349 this.Write(
"\t}\r\n}\r\n\r\n");
351 #line 78 "C:\DEV\paradox\sources\common\core\SiliconStudio.AssemblyProcessor.Common\ComplexSerializerCodeGenerator.tt"
354 foreach (var complexType
in cecilSerializerContext.ComplexTypes)
356 var complexClassSerializerGenerator =
new ComplexClassSerializerGenerator(complexType.Key, complexType.Value.ComplexSerializerProcessParentType);
357 Write(complexClassSerializerGenerator.TransformText());
362 return this.GenerationEnvironment.ToString();
372 [global::System.CodeDom.Compiler.GeneratedCodeAttribute(
"Microsoft.VisualStudio.TextTemplating",
"12.0.0.0")]
373 internal class ComplexSerializerCodeGeneratorBase
376 private global::System.Text.StringBuilder generationEnvironmentField;
377 private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
378 private global::System.Collections.Generic.List<
int> indentLengthsField;
379 private string currentIndentField =
"";
380 private bool endsWithNewline;
381 private global::System.Collections.Generic.IDictionary<string,
object> sessionField;
387 protected System.Text.StringBuilder GenerationEnvironment
391 if ((this.generationEnvironmentField == null))
393 this.generationEnvironmentField =
new global::System.Text.StringBuilder();
395 return this.generationEnvironmentField;
399 this.generationEnvironmentField = value;
405 public System.CodeDom.Compiler.CompilerErrorCollection Errors
409 if ((this.errorsField == null))
411 this.errorsField =
new global::System.CodeDom.Compiler.CompilerErrorCollection();
413 return this.errorsField;
419 private System.Collections.Generic.List<
int> indentLengths
423 if ((this.indentLengthsField == null))
425 this.indentLengthsField =
new global::System.Collections.Generic.List<
int>();
427 return this.indentLengthsField;
433 public string CurrentIndent
437 return this.currentIndentField;
443 public virtual global::System.Collections.Generic.IDictionary<string,
object>
Session
447 return this.sessionField;
451 this.sessionField = value;
455 #region Transform-time helpers
459 public void Write(
string textToAppend)
461 if (
string.IsNullOrEmpty(textToAppend))
467 if (((this.GenerationEnvironment.Length == 0)
468 ||
this.endsWithNewline))
470 this.GenerationEnvironment.Append(this.currentIndentField);
471 this.endsWithNewline =
false;
474 if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
476 this.endsWithNewline =
true;
480 if ((this.currentIndentField.Length == 0))
482 this.GenerationEnvironment.Append(textToAppend);
486 textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
489 if (this.endsWithNewline)
491 this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
495 this.GenerationEnvironment.Append(textToAppend);
501 public void WriteLine(
string textToAppend)
503 this.Write(textToAppend);
504 this.GenerationEnvironment.AppendLine();
505 this.endsWithNewline =
true;
510 public void Write(
string format, params
object[] args)
512 this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture,
format, args));
517 public void WriteLine(
string format, params
object[] args)
519 this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture,
format, args));
524 public void Error(
string message)
526 System.CodeDom.Compiler.CompilerError error =
new global::System.CodeDom.Compiler.CompilerError();
527 error.ErrorText = message;
528 this.Errors.Add(error);
533 public void Warning(
string message)
535 System.CodeDom.Compiler.CompilerError error =
new global::System.CodeDom.Compiler.CompilerError();
536 error.ErrorText = message;
537 error.IsWarning =
true;
538 this.Errors.Add(error);
543 public void PushIndent(
string indent)
545 if ((indent == null))
547 throw new global::System.ArgumentNullException(
"indent");
549 this.currentIndentField = (this.currentIndentField + indent);
550 this.indentLengths.Add(indent.Length);
555 public string PopIndent()
557 string returnValue =
"";
558 if ((this.indentLengths.Count > 0))
560 int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
561 this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
562 if ((indentLength > 0))
564 returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
565 this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
573 public void ClearIndent()
575 this.indentLengths.Clear();
576 this.currentIndentField =
"";
579 #region ToString Helpers
585 private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
589 public System.IFormatProvider FormatProvider
593 return this.formatProviderField ;
599 this.formatProviderField = value;
608 if ((objectToConvert == null))
610 throw new global::System.ArgumentNullException(
"objectToConvert");
612 System.Type t = objectToConvert.GetType();
613 System.Reflection.MethodInfo method = t.GetMethod(
"ToString",
new System.Type[] {
614 typeof(System.IFormatProvider)});
615 if ((method == null))
617 return objectToConvert.ToString();
621 return ((
string)(method.Invoke(objectToConvert,
new object[] {
622 this.formatProviderField })));
626 private ToStringInstanceHelper toStringHelperField =
new ToStringInstanceHelper();
630 public ToStringInstanceHelper ToStringHelper
634 return this.toStringHelperField;
Utility class to produce culture-oriented representation of an object as a string.
An error message (level 4).
string ToStringWithCulture(object objectToConvert)
This is called from the compile/run appdomain to convert objects within an expression block to a stri...
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
The template can be applied to an existing PackageSession.
A warning message (level 3).