Karteikarten
CodeDom C#
Karten in diesem Stapel (19)
- 1Code Compile UnitClass that Represents the file.
CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); - 2CodeNamespace and CodeNamespaceImportThe CodeNamspace class is used to represent the namespace.
codeNamespace = new CodeNamespace("Reflection"); - 3CodeNamespaceImportThe CodeNamespaceImport class is used to define the namespace you
would like to import. In C# you use the using keyword.
codeNamespace.Imports.Add(new CodeNamespaceImport("System")); - 4CodeTypeDeclarationThe next step is to declare the class.
CodeTypeDeclaration targetClass = new CodeTypeDeclaration("Calculator");
targetClass.IsClass = true;
targetClass.TypeAttributes = TypeAttributes.Public;
codeNamespace.Types.Add(targetClass); - 5CodeMemberFieldAddd the fields to the class.
CodeMemberField xField = new CodeMemberField();
xField.Name = "x";
xField.Type = new CodeTypeReference(typeof(double));
targetClass.Members.Add(xField); - 6CodeMemberPropertyCodeMemberProperty xProperty = new CodeMemberProperty();
- 7CodeMemberProperty getters and settersThe CodeMemberProperty class has two properties (HasGet and HasSet)
that you need to set to true. - 8GetStatementsThe GetStatements collection property
is used to add the code to the Get accessor. - 9CodeThisReferenceExpressionThe CodeThisReferenceExpression class is used because in C# you use this; in VB you use Me..
- 10SetStatementsThe SetStatements
collection property contains the code to set the this.x field. - 11CodeMemberMethodTo create methods using the CodeDOM, you need to
use the CodeMemberMethod class. - 12CodeMemberMethod.AttributesIt]s not the method atributes but the method decorators: public, static, final, new, private, etc.
- 13CodeConditionStatementif statements
ifLogic.Condition = new CodeBinaryOperatorExpression
ifLogic.TrueStatements.Add
ifLogic.FalseStatements.Add
divideMethod.Statements.Add(ifLogic); - 14CodeParameterDeclarationExpressionDefines the methods parameters
CodeParameterDeclarationExpression powerParameter =
new CodeParameterDeclarationExpression(typeof(double), "power");
exponentMethod.Parameters.Add(powerParameter); - 15CodeMethodInvokeExpressionThe
CodeMethodInvokeExpression class is used to call a method and pass a parameter to the method. - 16BracingStylethe BracingStyle property to “C” places the brackets, {}, on
separate lines. - 17CodeGeneratorOptionsThe
CodeGeneratorOptions class has properties that enable you to control the formatting of your automatically
generated code - 18TrueStatementsCodeConditionStatement used to add statements to the true path of logic using the CodeDOM
- 19CodeDOMProviderclass in the CodeDOM used to generate a class file
Informationen
- Beschreibung
- C# CodeDOM keywords and explanations
- Erstellt von
- Thiago Avelino
- Aufrufe
- 56
- Tags
- Bewertung