Add customize code to an existing code

질문 Add customize code to an existing code

  • 2012년 4월 3일 화요일 오전 1:15
     
     

    Hi

    I would like to create an application that can guide student what kind of code that he/she has to create. For this purpose, I use VSPackage and Roslyn. At the first stage, I like to add comment or #region directive directly to student code. For example, when the student is asked to write a program to change temperature from fahrenheit to celsius then when the student create his empty project, this code will be added to his source code.

    #region Write codes to enter temperature in Fahrenheit in here.

    #endregion

    #region Write mathematical formula to change the temperature from Fahrenheit to Celsius

    #endregion

    #region Display the temperature in Celsius

    #endregion

    How can I add these codes to the student source code?

    Many thanks

모든 응답

  • 2012년 4월 5일 목요일 오전 5:29
    소유자
     
     

    Hi,

    If all you want to do is modify what the initial project looks like, you can create a project that has that code, and then use the "Export Template" option from the File menu to create a new entry that will go in the New Project dialog.  This isn't something you need Roslyn, or even a VS Package to do.

    Hope this helps,


    -- Kevin Pilch-Bisson kevinpi@microsoft.com

  • 2012년 4월 5일 목요일 오전 6:22
     
     

    Hi PilchieMS,

    Thanks for the suggestion.

    However, what I want to do is to give different information (in the form #region my information) for each problem that must be solved by user/student. For example, at the first time, the student must write a program to change the temperature from fahrenheit to celsius. In this case, I will add some information to the project that is created by student such as my example above.

    If the student have finished this task, and the student is given the second task, for example, to find the area of a circle. In this case I will give different information to the student project.

    I use VSPackage to see what the student have done in their code and to give them another task when they have finished with the previous task that I gave them (as well as to check if they have had created a new project or not)

    Cheers.



    • 편집됨 b.hart 2012년 4월 5일 목요일 오전 6:24
    • 편집됨 b.hart 2012년 4월 5일 목요일 오전 6:27
    •  
  • 2012년 4월 5일 목요일 오후 5:20
    소유자
     
     

    I see.  In that case you should look into using a SyntaxRewriter to actually change the file, but you'll have to think about what sort of trigger you are going to use?  An explicit menu command maybe?


    -- Kevin Pilch-Bisson kevinpi@microsoft.com

  • 2012년 4월 6일 금요일 오전 12:18
     
     

    Thanks. I'll research SyntaxRewriter. Hopefully it's not to difficult to understand and some examples have been posted somewhere in the internet.

    For the trigger, I have a dialog box with button on it that is created using VSPackage.

    Thanks