Codedom, DOT NET Programming

Assignment Help:

What is CodeDom

The "CodeDom" is an object model that represents actually a source code. It is designed for language independent - once you create a "CodeDom" hierarchy for a program we can then generate the source code in any .NET language. So let's try to do some real practical and simple to just get a feel of how powerful "CodeDom" is.

We will try to generate the following code shown below. The below code which will be generated does not do any special thing by just displays a hello message and waits for the key to be clicked.

namespace InterviewQuestions

{

using System;

public class EntryPoint

{

public static void Main()

{

System.Console.WriteLine("Hello from Interview Question series");

System.Console.ReadLine();

}

}

}

The "Codedom" folder at the CD has one "GenerateCode" method that returns "CodeCompileUnit" object. The "CodeDom" is nothing but a full DOM model where every object in the structure shows a code unit. I have put some comments on the code so that the code is self understandable. I have put some comment at the code below so that readers can follow what is exactly happening. When you click the button it generates the "MyCode.cs" and also compiles the "Mycode.exe" in the "bin" folder.

private CodeCompileUnit GenerateCode()

{

// Definition of the Main method which will be entry point

CodeEntryPointMethod objMainMethod = new CodeEntryPointMethod();

objMainMethod.Name = "Main";

// generate this expression: Console

CodeTypeReferenceExpression consoleType = new CodeTypeReferenceExpression();

consoleType.Type = new CodeTypeReference(typeof(Console));

// Set up the argument list to pass to Console.WriteLine()

CodeExpression[] writeLineArgs = new CodeExpression[1];

CodePrimitiveExpression arg0 = new CodePrimitiveExpression("Hello from Interview

Question series");

writeLineArgs[0] = arg0;

// generate this statement: Console.WriteLine(message)

CodeMethodReferenceExpression writeLineRef = new

CodeMethodReferenceExpression(consoleType, "WriteLine");

CodeMethodInvokeExpression writeLine = new

CodeMethodInvokeExpression(writeLineRef, writeLineArgs);

// generate this statement: Console.ReadLine()

CodeMethodReferenceExpression readLineRef = new

CodeMethodReferenceExpression(consoleType, "ReadLine");

CodeMethodInvokeExpression readLine = new

CodeMethodInvokeExpression(readLineRef);

// Add Main() method to a class

CodeTypeDeclaration theClass = new CodeTypeDeclaration();

theClass.Members.Add(objMainMethod);

theClass.Name = "EntryPoint";

// Add both the code of WriteLine and Readline

objMainMethod.Statements.Add(writeLine);

objMainMethod.Statements.Add(readLine);

// Add namespace and add class

CodeNamespace ns = new CodeNamespace("InterviewQuestions");

ns.Imports.Add(new CodeNamespaceImport("System"));

ns.Types.Add(theClass);

// Generate the Compile Unit

CodeCompileUnit unit = new CodeCompileUnit();

unit.Namespaces.Add(ns);


Related Discussions:- Codedom

Describe the disconnected architecture of ado.net, Describe the disconnecte...

Describe the disconnected architecture of ADO.NET's data access model. ADO.NET maintains a disconnected database access model, which means, the application never remains linked

What does wsdl stand for, What does WSDL stand for?  WSDL stands for We...

What does WSDL stand for?  WSDL stands for Web Services Description Language.  It is an XML representation of the web service interface. There are two parts of the operation

Looking to build fifa coins selling and buying website, Looking to build FI...

Looking to build FIFA coins selling and buying website Project Description: I would like a website made for FIFA 14 TEAM. What this website will do is having automatically bu

Solving some issues about traffic jam, Computer programming Project Desc...

Computer programming Project Description: Solving some issues about traffic jam Skills required: C# Programming, Java, C++ Programming, PHP, Software Architecture

I need to develop a real state website, I need to Develop a real state webs...

I need to Develop a real state website We want a programmer who can create a website using html5, css3, jQuery, php, MySQL. All connected to a CRM to accomplish all the informat

Project life cycle, Explain project life cycle. Figure: -Life cyc...

Explain project life cycle. Figure: -Life cycle of a project There are 5 stages of any project initiating, planning, executing, controlling, & closeout. These are the

Webpage builder windows application, Webpage builder windows application + ...

Webpage builder windows application + source code + installer + user friendly interface. Project Description: Website Builder As its name suggests, the site builder should

Crystal Report base output, Hello, I want to develop one crystal report. I ...

Hello, I want to develop one crystal report. I have one database which has 5 field.One is string and others are Boolean. String field name is State and Four remaining fields are Th

Difference b/w msml and .net framework xml classes, What is the main differ...

What is the main difference b/w MSML and .NET Framework XML classes? The MSXML supports XML DOM and SAX parsers while the .NET framework XML classes support XML DOM and XML rea

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd