Exemplo n.º 1
0
        private static void InitializeTypeNameInfo(ParsedUnqualifiedName from, TypeNameInfo to)
        {
            to.Name          = from.Rootname;
            to.Namespace     = from.Namespace;
            to.IsGenericType = from.GenericParameters != null;

            if (to.IsGenericType)
            {
                to.IsOpenGeneric = from.GenericParameters.IsOpenGeneric;
                if (to.IsOpenGeneric)
                {
                    for (int i = 0; i < from.GenericParameters.Count; ++i)
                    {
                        to.GenericParameters.Add(null);
                    }
                }
                else
                {
                    foreach (var genericParam in from.GenericParameters.Parameters)
                    {
                        to.GenericParameters.Add(genericParam);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void InitializeTypeNameInfo(ParsedUnqualifiedName from, TypeNameInfo to)
        {
            to.Name = from.Rootname;
            to.Namespace = from.Namespace;
            to.IsGenericType = from.GenericParameters != null;

            if (to.IsGenericType)
            {
                to.IsOpenGeneric = from.GenericParameters.IsOpenGeneric;
                if (to.IsOpenGeneric)
                {
                    for (int i = 0; i < from.GenericParameters.Count; ++i)
                    {
                        to.GenericParameters.Add(null);
                    }
                }
                else
                {
                    foreach (var genericParam in from.GenericParameters.Parameters)
                    {
                        to.GenericParameters.Add(genericParam);
                    }
                }
            }
        }
Exemplo n.º 3
0
        // Parsing expressions from our grammar.
        private static ParseResult Match_TypeName(InputStream input)
        {
            var resultData = new TypeNameInfo();

            ParseResult result = Sequence(
                WithAction(Match_UnqualifiedName, r => InitializeTypeNameInfo((ParsedUnqualifiedName)r.ResultData, resultData)),
                ZeroOrOne(Sequence(Match_Comma, WithAction(Match_AssemblyName, r => resultData.AssemblyName = r.MatchedString))))(input);
            
            if (!result.Matched) return result;
            return new ParseResult(result.MatchedString, resultData);
        }
Exemplo n.º 4
0
 private static ParseResult Match_GenericTypeParameter(InputStream input)
 {
     return(FirstOf(
                WithAction(Match_UnqualifiedName, r =>
     {
         var result = new TypeNameInfo();
         InitializeTypeNameInfo((ParsedUnqualifiedName)r.ResultData, result);
         return new ParseResult(r.MatchedString, result);
     }),
                WithAction(Sequence(Match_LeftBracket, Match_TypeName, Match_RightBracket), r => new SequenceResult(r)[1]))
                (input));
 }
Exemplo n.º 5
0
        // Parsing expressions from our grammar.
        private static ParseResult Match_TypeName(InputStream input)
        {
            var resultData = new TypeNameInfo();

            ParseResult result = Sequence(
                WithAction(Match_UnqualifiedName, r => InitializeTypeNameInfo((ParsedUnqualifiedName)r.ResultData, resultData)),
                ZeroOrOne(Sequence(Match_Comma, WithAction(Match_AssemblyName, r => resultData.AssemblyName = r.MatchedString))))(input);

            if (!result.Matched)
            {
                return(result);
            }
            return(new ParseResult(result.MatchedString, resultData));
        }
Exemplo n.º 6
0
        private Type ResolveGenericTypeShorthand(string typeNameOrAlias)
        {
            Type         result      = null;
            TypeNameInfo parseResult = TypeNameParser.Parse(typeNameOrAlias);

            if (parseResult != null && parseResult.IsGenericType)
            {
                result = ResolveTypeInternal(parseResult.FullName);
                if (result == null)
                {
                    return(null);
                }

                var  genericParams = new List <Type>(parseResult.NumGenericParameters);
                bool isOpenGeneric = (parseResult.GenericParameters[0] == null);

                if (!isOpenGeneric)
                {
                    foreach (var genericParamInfo in parseResult.GenericParameters)
                    {
                        Type genericParam = ResolveType(genericParamInfo.FullName, false);
                        if (genericParam == null)
                        {
                            return(null);
                        }
                        genericParams.Add(genericParam);
                    }

                    if (genericParams.Count > 0)
                    {
                        result = result.MakeGenericType(genericParams.ToArray());
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
 private static ParseResult Match_GenericTypeParameter(InputStream input)
 {
     return ParseBuilder.FirstOf(
         ParseBuilder.WithAction(Match_UnqualifiedName, r =>
             {
                 var result = new TypeNameInfo();
                 InitializeTypeNameInfo((ParsedUnqualifiedName)r.ResultData, result);
                 return new ParseResult(r.MatchedString, result);
             }),
         ParseBuilder.WithAction(
             ParseBuilder.Sequence(Match_LeftBracket, Match_TypeName, Match_RightBracket),
                 r => new SequenceResult(r)[1]))(
         input);
 }