Example #1
0
        public override System.CodeDom.CodeExpression GCode_CodeDom_GetValue(CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context, CodeGenerateSystem.Base.GenerateCodeContext_PreNode preNodeContext = null)
        {
            var value1        = new System.CodeDom.CodeVariableReferenceExpression("System.DateTime.Now.Millisecond");
            var value2        = new System.CodeDom.CodePrimitiveExpression(0.001f);
            var arithmeticExp = new System.CodeDom.CodeBinaryOperatorExpression();

            arithmeticExp.Left     = value1;
            arithmeticExp.Right    = value2;
            arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Multiply;
            return(arithmeticExp);
        }
Example #2
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1    = typeof(bool);
            var valueType1Str = valueType1.FullName;

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    valueExp1 = condition;
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
            }
            else
            {
                var tempValueName1 = "InverterControl_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = valueExp1;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , InverterControlExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Example #3
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink || !mCtrlValue2.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1Str = linkObj1.GCode_GetTypeString(linkElm1, context);
            var valueType1    = linkObj1.GCode_GetType(linkElm1, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType1Str = "System.Boolean";
                valueType1    = typeof(bool);
            }
            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
                else
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
            }
            else
            {
                var tempValueName1 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 参数2
            var linkObj2 = mCtrlValue2.GetLinkedObject(0, true);
            var linkElm2 = mCtrlValue2.GetLinkedPinControl(0, true);

            if (!linkObj2.IsOnlyReturnValue)
            {
                await linkObj2.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm2, context);
            }

            System.CodeDom.CodeExpression valueExp2 = null;
            var valueType2Str = linkObj2.GCode_GetTypeString(linkElm2, context);
            var valueType2    = linkObj2.GCode_GetType(linkElm2, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType2Str = "System.Boolean";
                valueType2    = typeof(bool);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp2 = condition;
                }
                else
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
            }
            else
            {
                var tempValueName2 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value2";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value2))
                {
                    mVariableDeclarationStatement_Value2 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType2Str,
                        tempValueName2,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType2Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value2);
                }


                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                valueExp2 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName2);
            }
            //var valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);

            // 运算
            var arithmeticExp = new System.CodeDom.CodeBinaryOperatorExpression();

            arithmeticExp.Left  = valueExp1;
            arithmeticExp.Right = valueExp2;
            switch (CSParam.ConstructParam)
            {
            case "+":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Add;
                break;

            case "-":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Subtract;
                break;

            case "×":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Multiply;
                break;

            case "÷":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Divide;
                break;

            case "&&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanAnd;
                break;

            case "||":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanOr;
                break;

            case "&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseAnd;
                break;

            case "|":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseOr;
                break;
            }

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            if (!linkObj2.Pin_UseOrigionParamName(this.mCtrlValue2))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = arithmeticExp;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , arithmeticExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Example #4
0
 protected abstract void GenerateVariableReferenceExpression(System.CodeDom.CodeVariableReferenceExpression e);
Example #5
0
        public static object GetDbInfo(System.Data.DataSet ds)
        {
            // Get a code provider object.
            System.CodeDom.Compiler.CodeDomProvider cdp = new Microsoft.CSharp.CSharpCodeProvider();

            // Create the namespace and import the default "System" namespace.
            System.CodeDom.CodeNamespace nmspc = new System.CodeDom.CodeNamespace("DataExplorer");
            nmspc.Imports.Add(new System.CodeDom.CodeNamespaceImport("System"));
            nmspc.Imports.Add(new System.CodeDom.CodeNamespaceImport("System.ComponentModel"));

            // Create a class object.
            System.CodeDom.CodeTypeDeclaration clsDbInfo = new System.CodeDom.CodeTypeDeclaration("DbInfo");
            clsDbInfo.IsClass = true;
            nmspc.Types.Add(clsDbInfo);

            // Add fields to the class for each value returned.
            List <string> fldNms = new List <string>();

            for (int i = 0; i < ds.Tables.Count; i++)
            {
                for (int j = 0; j < ds.Tables[i].Columns.Count; j++)
                {
                    string fldNm = "_" + ds.Tables[i].Columns[j].ColumnName.ToLower();
                    if (!fldNms.Contains(fldNm))
                    {
                        System.CodeDom.CodeMemberField fld = new System.CodeDom.CodeMemberField(typeof(System.String), fldNm);
                        fld.Attributes = System.CodeDom.MemberAttributes.Public;
                        clsDbInfo.Members.Add(fld);
                        fldNms.Add(fldNm);
                    }
                }
            }

            // Add properties for the class to access each field.
            List <string> propNms = new List <string>();

            for (int i = 0; i < ds.Tables.Count; i++)
            {
                for (int j = 0; j < ds.Tables[i].Columns.Count; j++)
                {
                    string
                        fldNm  = "_" + ds.Tables[i].Columns[j].ColumnName.ToLower(),
                        propNm = ds.Tables[i].Columns[j].ColumnName;

                    if (!propNms.Contains(propNm))
                    {
                        System.CodeDom.CodeMemberProperty prop = new System.CodeDom.CodeMemberProperty();
                        prop.Attributes = System.CodeDom.MemberAttributes.Public;
                        prop.Name       = propNm;
                        prop.Type       = new System.CodeDom.CodeTypeReference(typeof(System.String));
                        System.CodeDom.CodeVariableReferenceExpression retExp    = new System.CodeDom.CodeVariableReferenceExpression(fldNm);
                        System.CodeDom.CodeMethodReturnStatement       getReturn = new System.CodeDom.CodeMethodReturnStatement(retExp);
                        prop.GetStatements.Add(getReturn);
                        prop.HasGet = true;
                        prop.HasSet = false;
                        string catName = (ds.Tables[i].TableName.EndsWith("1")) ? "File Group" : "Database";
                        System.CodeDom.CodeAttributeDeclaration attrCat = new System.CodeDom.CodeAttributeDeclaration("Category", new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodePrimitiveExpression(catName)));
                        prop.CustomAttributes.Add(attrCat);
                        // Add the property to our class.
                        clsDbInfo.Members.Add(prop);
                        propNms.Add(propNm);
                    }
                }
            }

            // Add a constructor to the class
            System.CodeDom.CodeConstructor clsDbInfoConstr = new System.CodeDom.CodeConstructor();
            clsDbInfoConstr.Attributes = System.CodeDom.MemberAttributes.Public;
            clsDbInfo.Members.Add(clsDbInfoConstr);

            // Create a CompileUnit for this new type.
            System.CodeDom.CodeCompileUnit cu = new System.CodeDom.CodeCompileUnit();
            cu.ReferencedAssemblies.Add("system.dll");
            cu.Namespaces.Add(nmspc);

            // Now, we're ready to generate some code!
#if DEBUG
            // If we're running in DEBUG mode, I want to see the generated code.
            using (System.IO.FileStream fs = new System.IO.FileStream("dbinfo.cs", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                using (System.IO.StreamWriter sr = new System.IO.StreamWriter(fs))
                    cdp.GenerateCodeFromCompileUnit(cu, sr, null);
#endif
            System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters();
            cp.ReferencedAssemblies.Add("system.dll");
            cp.GenerateExecutable      = false;
            cp.IncludeDebugInformation = false;
            cp.GenerateInMemory        = false;
            //cp.OutputAssembly = _outputName;
            System.CodeDom.Compiler.CompilerResults cr = cdp.CompileAssemblyFromDom(cp, cu);

            if (!cr.Errors.HasErrors)
            {
                System.Reflection.Assembly asm = cr.CompiledAssembly;
                object dbInfo = asm.CreateInstance("DataExplorer.DbInfo");
                return(dbInfo);
            }
            else
            {
                return(null);
            }
        }