Exemplo n.º 1
0
        protected override void CreateText(Dictionary <uint, NuGenTokenBase> allTokens)
        {
            base.CreateText(allTokens);
            TextBuilder.Length = 0;
            ReadSignature();

            if (signatureReader.CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_FIELD)
            {
                NuGenHelperFunctions.SetSignatureItemToken(allTokens, signatureReader.FieldSignatureItem);
                TextBuilder.Append(signatureReader.FieldSignatureItem);
            }
            else
            {
                string formatString1;
                string formatString2;

                TextBuilder.Append("(");

                if (signatureReader.Parameters != null)
                {
                    if (signatureReader.CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_LOCAL_SIG)
                    {
                        formatString1 = "{0} V_{1},\n";
                        formatString2 = "{0} V_{1}";
                    }
                    else
                    {
                        formatString1 = "{0}, ";
                        formatString2 = "{0}";

                        NuGenHelperFunctions.SetSignatureItemToken(allTokens, signatureReader.ReturnType);
                        TextBuilder.Insert(0, " ");
                        TextBuilder.Insert(0, signatureReader.ReturnType);
                        TextBuilder.Insert(0, " ");
                        TextBuilder.Insert(0, NuGenHelperFunctions.GetCallingConventionName(signatureReader.CallingConvention));
                    }

                    for (int index = 0; index < signatureReader.Parameters.Count; index++)
                    {
                        NuGenBaseSignatureItem signatureItem = signatureReader.Parameters[index];
                        NuGenHelperFunctions.SetSignatureItemToken(allTokens, signatureItem);

                        if (signatureReader.CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_LOCAL_SIG && index > 0)
                        {
                            TextBuilder.Append("      ");
                        }

                        if (signatureReader.Parameters.Count > 1 && index < signatureReader.Parameters.Count - 1)
                        {
                            TextBuilder.AppendFormat(formatString1, signatureItem, index);
                        }
                        else
                        {
                            TextBuilder.AppendFormat(formatString2, signatureItem, index);
                        }
                    }
                }

                TextBuilder.Append(")");
            }

            Text = TextBuilder.ToString();
        }
Exemplo n.º 2
0
        public string GetDefinition(string className, string methodName, bool functionPointer)
        {
            string methodDescription = string.Empty;
            string returnTypeText    = string.Empty;
            string callingConvention = NuGenHelperFunctions.GetCallingConventionName(CallingConvention);

            NuGenHelperFunctions.SetSignatureItemToken(AllTokens, ReturnType);
            returnTypeText = ReturnType.ToString();

            StringBuilder parameterList = new StringBuilder();

            if (functionPointer)
            {
                parameterList.Append("*");
            }

            parameterList.Append("(");

            if (Parameters != null)
            {
                for (int parametersIndex = 0; parametersIndex < Parameters.Count; parametersIndex++)
                {
                    NuGenBaseSignatureItem parameter = Parameters[parametersIndex];
                    NuGenHelperFunctions.SetSignatureItemToken(AllTokens, parameter);

                    if (parametersIndex == Parameters.Count - 1)
                    {
                        parameterList.Append(parameter);
                    }
                    else
                    {
                        parameterList.AppendFormat("{0}, ", parameter);
                    }
                }
            }

            if (SentinelFound)
            {
                if (Parameters != null)
                {
                    parameterList.Append(", ");
                }

                parameterList.Append("...");

                if (VarargParameters != null)
                {
                    parameterList.Append(", ");

                    for (int index = 0; index < VarargParameters.Count; index++)
                    {
                        NuGenBaseSignatureItem varargParameter = VarargParameters[index];
                        NuGenHelperFunctions.SetSignatureItemToken(AllTokens, varargParameter);

                        if (index == VarargParameters.Count - 1)
                        {
                            parameterList.Append(varargParameter);
                        }
                        else
                        {
                            parameterList.AppendFormat("{0}, ", varargParameter);
                        }
                    }
                }
            }
            parameterList.Append(")");

            StringBuilder textBuilder = new StringBuilder();

            if (callingConvention.Length > 0)
            {
                textBuilder.AppendFormat("{0} ", callingConvention);
            }

            textBuilder.AppendFormat("{0} ", returnTypeText);

            textBuilder.AppendFormat("{0}{1}{2}{3}", className, (className == null ? string.Empty : "::"), methodName, parameterList.ToString());

            return(textBuilder.ToString());
        }