예제 #1
0
        protected override IValue VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
        {
            var nodeInfo = ModelExtensions.GetSymbolInfo(Model, node);

            // var t = model.GetTypeInfo(node);
            if (nodeInfo.Symbol == null)
            {
                var tmp = node.FindParentNode <MethodDeclarationSyntax>();
                if (tmp != null)
                {
                    var headerInfo = context.GetMethodMethodHeaderInfo(tmp);
                    var ti         = ModelExtensions.GetTypeInfo(_state.Context.RoslynModel, node);
                    var ti2        = ti.Type;
                    if (ti2 != null)
                    {
                        var ti3 = context.Roslyn_ResolveType(ti2);
                        if (ti3 != null)
                        {
                            var g = headerInfo.TypeParameterConstraints.FirstOrDefault(a => a.Type == ti3);
                            if (g != null && g.RequiresParameterlessConstructor)
                            {
                                headerInfo.PassTypeName(ti3);
                            }
                        }
                    }
                }

                throw new NullReferenceException("nodeInfo.Symbol");
            }

            var methodSymbol = nodeInfo.Symbol as IMethodSymbol;

            var constructorInfo = context.Roslyn_ResolveMethod(methodSymbol) as ConstructorInfo;

            if (constructorInfo == null)
            {
                throw new NotSupportedException();
            }
            var argList = _internalVisitArgumentList(node.ArgumentList);

            IValue[] initializer = null;

            {
                if (node.Initializer != null)
                {
                    var initializer1 = Visit(node.Initializer);
                    if (initializer1 == null)
                    {
                        throw new ArgumentNullException(nameof(initializer1));
                    }
                    if (initializer1 is IValueTable2_PseudoValue)
                    {
                        initializer = (initializer1 as IValueTable2_PseudoValue).Items.OfType <IValue>().ToArray();
                    }
                    else if (initializer1 is IValueTable_PseudoValue)
                    {
                        initializer = (initializer1 as IValueTable_PseudoValue).Items;
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            }
            if (initializer == null)
            {
                initializer = new IValue[0];
            }
            var co = new CallConstructor(constructorInfo, argList, initializer);

            return(co);
        }