Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using CodeDOM in .NET to generate an assignment statement inside a property of a class

Using CodeDOM in .NET to generate an assignment statement inside a property of a class

Scheduled Pinned Locked Moved C#
csharphelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rameshbhojan
    wrote on last edited by
    #1

    Could anyone please help me out in auto-generating a property in a class in a following format: public System.Int64 RollNumber { get { System.Int64 rollNo = (System.Int64 )this["@roll_number"]; return rollNo; } } I am able to generate the property with the return statement and the other stuff, but i am not able to Generate the assignment statement i,e : System.Int64 rollNo = (System.Int64 )this["@roll_number"]; Please Help. Thanks, Ramesh

    L I 2 Replies Last reply
    0
    • R rameshbhojan

      Could anyone please help me out in auto-generating a property in a class in a following format: public System.Int64 RollNumber { get { System.Int64 rollNo = (System.Int64 )this["@roll_number"]; return rollNo; } } I am able to generate the property with the return statement and the other stuff, but i am not able to Generate the assignment statement i,e : System.Int64 rollNo = (System.Int64 )this["@roll_number"]; Please Help. Thanks, Ramesh

      L Offline
      L Offline
      Lutoslaw
      wrote on last edited by
      #2

      rameshbhojan wrote:

      auto-generating

      ? Did you mean this?

      public System.Int64 RollNumber
      {
      get
      {
      System.Int64 rollNo = (System.Int64 )this["@roll_number"];
      return rollNo;
      }
      set
      {
      this["@roll_number"] = (proper_cast)value;
      }
      }

      Greetings - Gajatko

      R 1 Reply Last reply
      0
      • L Lutoslaw

        rameshbhojan wrote:

        auto-generating

        ? Did you mean this?

        public System.Int64 RollNumber
        {
        get
        {
        System.Int64 rollNo = (System.Int64 )this["@roll_number"];
        return rollNo;
        }
        set
        {
        this["@roll_number"] = (proper_cast)value;
        }
        }

        Greetings - Gajatko

        R Offline
        R Offline
        rameshbhojan
        wrote on last edited by
        #3

        Hi Gajatko, All i wanna generate is : public System.Int64 RollNumber { get { System.Int64 rollNo = (System.Int64 )this["@roll_number"]; return rollNo; } } i don need the set statement.... anyways gimme the solution you have...... if i am able to generate the way you said then also it is fine!!!! Thanks, Ramesh

        1 Reply Last reply
        0
        • R rameshbhojan

          Could anyone please help me out in auto-generating a property in a class in a following format: public System.Int64 RollNumber { get { System.Int64 rollNo = (System.Int64 )this["@roll_number"]; return rollNo; } } I am able to generate the property with the return statement and the other stuff, but i am not able to Generate the assignment statement i,e : System.Int64 rollNo = (System.Int64 )this["@roll_number"]; Please Help. Thanks, Ramesh

          I Offline
          I Offline
          Insincere Dave
          wrote on last edited by
          #4

          The class your looking for is CodeVariableDeclarationStatement.

          CodeMemberProperty prop = new CodeMemberProperty();
          prop.Name = "RollNumber";
          prop.HasGet = true;
          prop.Attributes = MemberAttributes.Public;
          prop.Type = new CodeTypeReference("System.Int64");

          prop.GetStatements.Add(new CodeVariableDeclarationStatement("System.Int64", "rollNo",
          new CodeCastExpression("System.Int64",
          new CodeIndexerExpression(
          new CodeThisReferenceExpression(),
          new CodePrimitiveExpression(
          "@roll_number")))));
          prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("rollNo")));

          But why bother with the variable when you could just return (System.Int64 )this["@roll_number"];

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups