GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

CodeDom C#

Thiago Avelino Portugiesisch 19 Karten

Karten in diesem Stapel (19)

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

Informationen

Beschreibung
C# CodeDOM keywords and explanations
Erstellt von
Thiago Avelino
Aufrufe
56
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck