locked
AddFunction generates a function with return type when passed vsCMFunctionConstructor. RRS feed

  • Question

  • When using the VCFileCodeModel or the FileCodeModel interface to create a constructor by passing vsCMFunction.vsCMFunctionConstructor as the functionkind for the AddFunction function, the constructor gains a return type.

    This piece of code is what i want to generate:

    X::X()
    {
    }

    Calling this generates a function with return type (source being a FileCodeModel representing a source file):

    source.AddFunction("X::X" , vsCMFunction.vsCMFunctionConstructor, null, -1,vsCMAccess.vsCMAccessDefault);

    replacing the null with any of these values make no difference:

    "X"

    vsCMTypeRef.vsCMTypeRefVoid

    vsCMTypeRef.vsCMTypeRefCodeType

    vsCMTypeRef.vsCMTypeRefOther

    Everyone except the "X" string as a return type defaults to int like below:

    int X::X()
    {
    }



    • Edited by DevArch Thursday, December 26, 2013 6:51 PM Cleanup
    Thursday, December 26, 2013 6:31 PM

Answers

  • This piece of code is what i want to generate:

    X::X()
    {
    }

    Calling this generates a function with return type (source being a FileCodeModel representing a source file):

    source.AddFunction("X::X" , vsCMFunction.vsCMFunctionConstructor, null, -1,vsCMAccess.vsCMAccessDefault);

    First, please accept my apology for the inappropriate suggestions in my previous reply.

    The return value of both VCFileCodeModel::AddFunction Method   and  FileCodeModel::AddFunction Method is a CodeFunction object.

    Since the type of this constructor is always int,please try to use the CodeFunction.Kind Property to testify this problem, which returns an enumeration indicating the type of object.

    Besides,please take a look at the following information:

    The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

    The following is one related document:

    Visual C++ Code Model.

    In addition, please share more code so that we could have a better understanding of this issue.You can post it here or upload it on https://skydrive.live.com/ .

    Thanks for your understanding.

    Sincerely,

    Jane.

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 30, 2013 9:42 AM

All replies

  • Hello,

    Welcome to MSDN forum.

    Please try to use  vsCMFunction.vsCMFunctionFunction instead of vsCMFunction.vsCMFunctionConstructor for the AddFunction.For more details,please refer to vsCMFunction Enumeration .

    In addition, you could check the sample code in the following links:

    How to: Create a C# Class by Using the CodeModel Object

    Adding or Changing Code using FileCodeModel in Visual Studio .Net

    Best Regards,

    Jane.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 27, 2013 7:37 AM
  • Please try to use  vsCMFunction.vsCMFunctionFunction instead of vsCMFunction.vsCMFunctionConstructor for the AddFunction.

    How to: Create a C# Class by Using the CodeModel Object

    Adding or Changing Code using FileCodeModel in Visual Studio .Net



    That did most certainly NOT help. I WANT to generate a constructor. That is a function WITHOUT return type. This is never discussed in any of your links.

    • Edited by DevArch Saturday, December 28, 2013 1:57 AM
    Saturday, December 28, 2013 1:53 AM
  • This piece of code is what i want to generate:

    X::X()
    {
    }

    Calling this generates a function with return type (source being a FileCodeModel representing a source file):

    source.AddFunction("X::X" , vsCMFunction.vsCMFunctionConstructor, null, -1,vsCMAccess.vsCMAccessDefault);

    First, please accept my apology for the inappropriate suggestions in my previous reply.

    The return value of both VCFileCodeModel::AddFunction Method   and  FileCodeModel::AddFunction Method is a CodeFunction object.

    Since the type of this constructor is always int,please try to use the CodeFunction.Kind Property to testify this problem, which returns an enumeration indicating the type of object.

    Besides,please take a look at the following information:

    The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

    The following is one related document:

    Visual C++ Code Model.

    In addition, please share more code so that we could have a better understanding of this issue.You can post it here or upload it on https://skydrive.live.com/ .

    Thanks for your understanding.

    Sincerely,

    Jane.

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 30, 2013 9:42 AM