Пример #1
0
        /// <summary>
        /// Old VS projects had some pretty messed-up looking values for the
        /// "DefineConstants" property.  It worked fine in the IDE, because it
        /// effectively munged up the string so that it ended up being valid for
        /// the compiler.  We do the equivalent munging here now.
        ///
        /// Basically, we take the incoming string, and split it on comma/semicolon/space.
        /// Then we look at the resulting list of strings, and remove any that are
        /// illegal identifiers, and pass the remaining ones through to the compiler.
        ///
        /// Note that CSharp does support assigning a value to the constants ... in
        /// other words, a constant is either defined or not defined ... it can't have
        /// an actual value.
        /// </summary>
        internal string GetDefineConstantsSwitch
        (
            string originalDefineConstants
        )
        {
            if (originalDefineConstants == null)
            {
                return(null);
            }

            StringBuilder finalDefineConstants = new StringBuilder();

            // Split the incoming string on comma/semicolon/space.
            string[] allIdentifiers = originalDefineConstants.Split(new char[] { ',', ';', ' ' });

            // Loop through all the parts, and for the ones that are legal C# identifiers,
            // add them to the outgoing string.
            foreach (string singleIdentifier in allIdentifiers)
            {
                if (Csc.IsLegalIdentifier(singleIdentifier))
                {
                    // Separate them with a semicolon if there's something already in
                    // the outgoing string.
                    if (finalDefineConstants.Length > 0)
                    {
                        finalDefineConstants.Append(";");
                    }

                    finalDefineConstants.Append(singleIdentifier);
                }
                else if (singleIdentifier.Length > 0)
                {
                    Log.LogWarningWithCodeFromResources("Csc.InvalidParameterWarning", "/define:", singleIdentifier);
                }
            }

            if (finalDefineConstants.Length > 0)
            {
                return(finalDefineConstants.ToString());
            }
            else
            {
                // We wouldn't want to pass in an empty /define: switch on the csc.exe command-line.
                return(null);
            }
        }
Пример #2
0
        internal string GetDefineConstantsSwitch(string originalDefineConstants)
        {
            if (originalDefineConstants == null)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            string[] array = originalDefineConstants.Split(new char[]
            {
                ',',
                ';',
                ' '
            });
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text = array2[i];
                if (Csc.IsLegalIdentifier(text))
                {
                    if (stringBuilder.Length > 0)
                    {
                        stringBuilder.Append(";");
                    }
                    stringBuilder.Append(text);
                }
                else
                {
                    if (text.Length > 0)
                    {
                        base.Log.LogWarningWithCodeFromResources("Csc.InvalidParameterWarning", new object[]
                        {
                            "/define:",
                            text
                        });
                    }
                }
            }
            if (stringBuilder.Length > 0)
            {
                return(stringBuilder.ToString());
            }
            return(null);
        }