Serialize() public method

Serializes current QvxTableHeader object into an XML document
public Serialize ( ) : string
return string
Ejemplo n.º 1
0
        public QvxWriteCode(Type type, Dictionary<string, List<QvxBaseAttribute>> overrideAttributes)
        {
            var data = QvxData.FromObjectCode(type, overrideAttributes);
            qvxTableHeader = new QvxTableHeader();
            qvxTableHeader.TableName = type.Name;
            qvxTableHeader.Fields.AddRange(data.Item1);
            QvxHeader = Encoding.UTF8.GetBytes(qvxTableHeader.Serialize());

            #region Code Template
            string code = @"
            namespace QvxLib {
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Reflection;
            using System.Reflection.Emit;
            using System.IO;

            public static class FieldInfoExtensions
            {
            public static DynamicMethod GetGetMethod(this FieldInfo fi)
            {
            DynamicMethod dm = new DynamicMethod(""Get"" + fi.Name,
                fi.FieldType, new Type[] { fi.DeclaringType }, fi.DeclaringType);
            ILGenerator il = dm.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, fi);
            il.Emit(OpCodes.Ret);
            return dm;
            }
            }

            public class QvxWriterClass
            {
            public static void QvxWriter(BinaryWriter bw, IEnumerable<object> list)
            {
            object tmpValue = null;
            byte[] sbuf = null;
            StringBuilder sb = null;

            Type T_base__ = list.GetType().GetInterface(typeof(IEnumerable<>).Name).GetGenericArguments()[0];
            " + data.Item2 + @"
            foreach (var base__item in list)
            {
            " + data.Item3 + @"
            }
            }
            }
            }";
            #endregion

            #region Compiler Paramater
            CompilerParameters compilerParams = new CompilerParameters()
            {
                CompilerOptions = "/target:library /optimize /define:RELEASE",
                GenerateExecutable = false,
                WarningLevel = 3,
                GenerateInMemory = true,
                IncludeDebugInformation = false,
                ReferencedAssemblies = { "mscorlib.dll", "System.dll", "System.Core.dll" }
            };
            #if DEBUG
            compilerParams.CompilerOptions = "/target:library /define:DEBUG";
            compilerParams.GenerateInMemory = false;
            compilerParams.IncludeDebugInformation = true;
            compilerParams.TempFiles.KeepFiles = true;
            compilerParams.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
            #endif
            #endregion

            var provOptions = new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } };

            CodeDomProvider codeProvider = new CSharpCodeProvider(provOptions);
            CompilerResults results = codeProvider.CompileAssemblyFromSource(compilerParams, code);

            if (!results.Errors.HasErrors)
            {
                var QvxWriterClassType = results.CompiledAssembly.GetType("QvxLib.QvxWriterClass");
                QvxWriterMethod = QvxWriterClassType.GetMethod("QvxWriter", BindingFlags.Static | BindingFlags.Public);
            }
            else
                throw new Exception("Compilation Error" + results.Output.ToString());
        }
Ejemplo n.º 2
0
        public QvxWriteCode(Type type, Dictionary <string, List <QvxBaseAttribute> > overrideAttributes)
        {
            var data = QvxData.FromObjectCode(type, overrideAttributes);

            qvxTableHeader           = new QvxTableHeader();
            qvxTableHeader.TableName = type.Name;
            qvxTableHeader.Fields.AddRange(data.Item1);
            QvxHeader = Encoding.UTF8.GetBytes(qvxTableHeader.Serialize());



            #region Code Template
            string code = @"
namespace QvxLib { 
    using System; 
    using System.Collections.Generic;
    using System.Linq;
    using System.Text; 
    using System.Reflection;
    using System.Reflection.Emit;
    using System.IO; 


    public static class FieldInfoExtensions
    {
        public static DynamicMethod GetGetMethod(this FieldInfo fi)
        {       
            DynamicMethod dm = new DynamicMethod(""Get"" + fi.Name,
                fi.FieldType, new Type[] { fi.DeclaringType }, fi.DeclaringType);
            ILGenerator il = dm.GetILGenerator();          
            il.Emit(OpCodes.Ldarg_0);            
            il.Emit(OpCodes.Ldfld, fi);            
            il.Emit(OpCodes.Ret);
            return dm;
        }
    }

    public class QvxWriterClass 
    { 
        public static void QvxWriter(BinaryWriter bw, IEnumerable<object> list) 
        {           
            object tmpValue = null;    
            byte[] sbuf = null; 
            StringBuilder sb = null;    
                          
            Type T_base__ = list.GetType().GetInterface(typeof(IEnumerable<>).Name).GetGenericArguments()[0];
" + data.Item2 + @"                        
            foreach (var base__item in list) 
            {
" + data.Item3 + @"
            }
        }
    }
}";
            #endregion

            #region Compiler Paramater
            CompilerParameters compilerParams = new CompilerParameters()
            {
                CompilerOptions         = "/target:library /optimize /define:RELEASE",
                GenerateExecutable      = false,
                WarningLevel            = 3,
                GenerateInMemory        = true,
                IncludeDebugInformation = false,
                ReferencedAssemblies    = { "mscorlib.dll", "System.dll", "System.Core.dll" }
            };
#if DEBUG
            compilerParams.CompilerOptions         = "/target:library /define:DEBUG";
            compilerParams.GenerateInMemory        = false;
            compilerParams.IncludeDebugInformation = true;
            compilerParams.TempFiles.KeepFiles     = true;
            compilerParams.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
#endif
            #endregion

            var provOptions = new Dictionary <string, string>()
            {
                { "CompilerVersion", "v3.5" }
            };

            CodeDomProvider codeProvider = new CSharpCodeProvider(provOptions);
            CompilerResults results      = codeProvider.CompileAssemblyFromSource(compilerParams, code);

            if (!results.Errors.HasErrors)
            {
                var QvxWriterClassType = results.CompiledAssembly.GetType("QvxLib.QvxWriterClass");
                QvxWriterMethod = QvxWriterClassType.GetMethod("QvxWriter", BindingFlags.Static | BindingFlags.Public);
            }
            else
            {
                throw new Exception("Compilation Error" + results.Output.ToString());
            }
        }