FlatRedBall.Glue.Parsing.ParsedMethod.FillGenericRestrictions C# (CSharp) Méthode

FillGenericRestrictions() public static méthode

public static FillGenericRestrictions ( string lineOfCode, List GenericTypes, List ArgumentList ) : void
lineOfCode string
GenericTypes List
ArgumentList List
Résultat void
        public static void FillGenericRestrictions(string lineOfCode, List<ParsedType> GenericTypes, List<ParsedField> ArgumentList)
        {
            // Vic says - this only handles one constraint on one generic type.
            // If it gets more complicated than that, this needs to be modified.

            if (GenericTypes.Count != 0 && lineOfCode.Contains("where "))
            {
                int m = 3;

                string constraintsString = lineOfCode.Substring(lineOfCode.IndexOf("where "));

                string constraint = constraintsString.Substring(constraintsString.IndexOf(": ") + 2);

                // Let's separate em and build em back because we gotta get rid of things like "new()"
                if (constraint.Contains(","))
                {
                    string[] splitConstraints = constraint.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                    constraintsToUse.Clear();

                    foreach (string individualConstraint in splitConstraints)
                    {
                        string trimmed = individualConstraint.Trim();

                        if (trimmed != "new()")
                        {
                            constraintsToUse.Add(trimmed);
                        }
                    }
                    constraint = "";
                    for (int i = 0; i < constraintsToUse.Count; i++)
                    {
                        if (i == constraintsToUse.Count - 1)
                        {
                            constraint += constraintsToUse[i];
                        }
                        else
                        {
                            constraint += constraintsToUse[i] + ", ";
                        }
                    }
                }

                GenericTypes[0].GenericRestrictions.Add(constraint);

            }

            for(int i = 0; i < GenericTypes.Count; i++)
            {
                ParsedType genericType = GenericTypes[i];
                foreach (ParsedField parsedField in ArgumentList)
                {
                    if (parsedField.Type.GenericType != null && parsedField.Type.GenericType.Name == genericType.Name)
                    {
                        parsedField.Type.GenericRestrictions.AddRange(genericType.GenericRestrictions);

                    }
                }
            }
        }

Same methods

ParsedMethod::FillGenericRestrictions ( string lineOfCode ) : void

Usage Example

        private void CreateParsedMethod(int startIndex, int endIndex, bool trimContents)
        {
            // For now we'll assume that all properties are on
            // the same line.  Eventually we may want to combine
            // all lines before the opening bracket


            // todo: add attributes:
            CurrentAttributes.Clear();


            #region Get header information

            int lineIndexForHeader = 0;

            string headerLine = mCurrentBlock[lineIndexForHeader].Trim();

            int numberOfParens = mCurrentBlock[lineIndexForHeader].CountOf('(') - mCurrentBlock[lineIndexForHeader].CountOf(')');


            while (numberOfParens > 0)
            {
                lineIndexForHeader++;
                headerLine += " " + mCurrentBlock[lineIndexForHeader].Trim();

                numberOfParens += mCurrentBlock[lineIndexForHeader].CountOf('(') - mCurrentBlock[lineIndexForHeader].CountOf(')');
            }

            ParsedMethod parsedMethod = new ParsedMethod();

            parsedMethod.FillHeaderInformation(headerLine);

            #endregion

            parsedMethod.StartIndex = startIndex;
            parsedMethod.EndIndex   = endIndex;

            parsedMethod.FillArgumentList(parsedMethod, mCurrentBlock, 0, true);

            // Fill generic restrictions after getting all arguments
            parsedMethod.FillGenericRestrictions(headerLine);

            parsedMethod.FillBaseCall(mCurrentBlock);

            StringBuilder methodContents = new StringBuilder();

            bool hasGetter;
            bool hasSetter;

            bool hasAutomaticGetter;
            bool hasAutomaticSetter;

            FillGettersAndSetters(methodContents, methodContents, false, trimContents, out hasGetter, out hasSetter, out hasAutomaticGetter, out hasAutomaticSetter);

            parsedMethod.MethodContents = methodContents.ToString();
            parsedMethod.StoreOffOldName();

            mParsedMethods.Add(parsedMethod);
        }
All Usage Examples Of FlatRedBall.Glue.Parsing.ParsedMethod::FillGenericRestrictions