Exemplo n.º 1
0
        private static void ProcessInitializer(OutputWriter writer, VariableDeclarationSyntax declaration,
                                               VariableDeclaratorSyntax variable)
        {
            var initializer = variable.Initializer;

            if (initializer != null)
            {
                if (CSharpExtensions.CSharpKind(initializer.Value) == SyntaxKind.CollectionInitializerExpression)
                {
                    return;
                }
                var value                  = initializer.Value;
                var initializerType        = TypeProcessor.GetTypeInfo(value);
                var memberaccessexpression = value as MemberAccessExpressionSyntax;
                var nameexpression         = value as NameSyntax;
                var nullAssignment         = value.ToFullString().Trim() == "null";
                var shouldBox              = initializerType.Type != null && (initializerType.Type.IsValueType) &&
                                             !initializerType.ConvertedType.IsValueType;
                var shouldUnBox = initializerType.Type != null && !initializerType.Type.IsValueType &&
                                  initializerType.ConvertedType.IsValueType;
                var isname             = value is NameSyntax;
                var ismemberexpression = value is MemberAccessExpressionSyntax ||
                                         (isname &&
                                          TypeProcessor.GetSymbolInfo(value as NameSyntax).Symbol.Kind ==
                                          SymbolKind.Method);
                var isdelegateassignment = ismemberexpression &&
                                           initializerType.ConvertedType.TypeKind == TypeKind.Delegate;
                var isstaticdelegate = isdelegateassignment &&
                                       ((memberaccessexpression != null &&
                                         TypeProcessor.GetSymbolInfo(memberaccessexpression).Symbol.IsStatic) ||
                                        (isname && TypeProcessor.GetSymbolInfo(nameexpression).Symbol.IsStatic));
                var shouldCast = initializerType.Type != initializerType.ConvertedType &&
                                 initializerType.ConvertedType != null;

                if (nullAssignment)
                {
                    if (initializerType.Type != null) //Nullable Support
                    {
                        if (initializerType.Type.Name == "Nullable")
                        {
                            var atype = TypeProcessor.ConvertType(initializerType.Type);
                            writer.Write(atype + "()");
                        }
                    }
                    else
                    {
                        writer.Write("null");
                    }

                    return;
                }
                if (shouldBox)
                {
//Box
                    writer.Write("BOX!(" + TypeProcessor.ConvertType(initializerType.Type) + ")(");
//When passing an argument by ref or out, leave off the .Value suffix
                    Core.Write(writer, value);
                    writer.Write(")");
                    return;
                }
                if (shouldUnBox)
                {
                    writer.Write("cast(" + TypeProcessor.ConvertType(initializerType.Type) + ")(");
                    Core.Write(writer, value);
                    writer.Write(")");
                    return;
                }
                if (initializer.Parent.Parent.Parent is FixedStatementSyntax) // Fixed is a bit special
                {
//TODO write a better fix
                    var type = TypeProcessor.GetTypeInfo(declaration.Type);

                    writer.Write("cast(" + TypeProcessor.ConvertType(type.Type) + ")(");
                    Core.Write(writer, value);
                    writer.Write(")");
                    return;
                }
                if (isdelegateassignment)
                {
                    var typeString = TypeProcessor.ConvertType(initializerType.ConvertedType);

                    var createNew = !(value is ObjectCreationExpressionSyntax);

                    if (createNew)
                    {
                        if (initializerType.ConvertedType.TypeKind == TypeKind.TypeParameter)
                        {
                            writer.Write(" __TypeNew!(" + typeString + ")(");
                        }
                        else
                        {
                            writer.Write("new " + typeString + "(");
                        }
                    }

                    var isStatic = isstaticdelegate;
                    //                    if (isStatic)
                    //                        writer.Write("__ToDelegate(");
                    MemberUtilities.WriteMethodPointer(writer, value);
                    //                    if (isStatic)
                    //                        writer.Write(")");

                    if (createNew)
                    {
                        writer.Write(")");
                    }
                    return;
                }
                if (initializerType.Type == null && initializerType.ConvertedType == null)
                {
                    writer.Write("null");
                    return;
                }
                Core.Write(writer, value);
            }
            else
            {
                writer.Write(TypeProcessor.DefaultValue(declaration.Type));
            }
        }
Exemplo n.º 2
0
        private static void ProcessInitializer(OutputWriter writer, LocalDeclarationStatementSyntax declaration,
                                               VariableDeclaratorSyntax variable)
        {
            var initializer = variable.Initializer;

            if (initializer != null)
            {
                if (initializer.Value.CSharpKind() == SyntaxKind.CollectionInitializerExpression)
                {
                    return;
                }

                var value                  = initializer.Value;
                var initializerType        = TypeProcessor.GetTypeInfo(value);
                var memberaccessexpression = value as MemberAccessExpressionSyntax;
                var nameexpression         = value as NameSyntax;
                var nullAssignment         = value.ToFullString().Trim() == "null";
                var convertedType          = initializerType.ConvertedType;
                var type = initializerType.Type;
                if (type == null && convertedType == null) //TODO: Rare Case (Compiling csnative corlib... need to find a solution, for now just write it out
                {
                    Core.Write(writer, value);
                    return;
                }

                var shouldBox = type != null && (type.IsValueType) &&
                                !convertedType.IsValueType;
                var shouldUnBox = type != null && !type.IsValueType &&
                                  convertedType.IsValueType;
                var isname             = value is NameSyntax;
                var ismemberexpression = value is MemberAccessExpressionSyntax ||
                                         (isname &&
                                          TypeProcessor.GetSymbolInfo(value as NameSyntax).Symbol.Kind ==
                                          SymbolKind.Method);


                var isdelegateassignment = ismemberexpression &&
                                           convertedType.TypeKind == TypeKind.Delegate;
                var isstaticdelegate = isdelegateassignment &&
                                       ((memberaccessexpression != null &&
                                         TypeProcessor.GetSymbolInfo(memberaccessexpression).Symbol.IsStatic) ||
                                        (isname && TypeProcessor.GetSymbolInfo(nameexpression).Symbol.IsStatic));

                //Do we have an implicit converter, if so, use it
                if (shouldBox || shouldUnBox)
                {
                    if (WriteConverter(writer, type, convertedType, value))
                    {
                        return;
                    }
                }

                if (nullAssignment)
                {
                    if (convertedType != null) //Nullable Support
                    {
                        if (convertedType.Name == "Nullable")
                        {
                            var atype = TypeProcessor.ConvertType(convertedType);
                            writer.Write(atype + "()");
                        }
                        else
                        {
                            writer.Write("null");
                        }
                    }
                    return;
                }
                if (shouldBox)
                {
                    WriteBox(writer, type, value);
                    return;
                }
                if (shouldUnBox)
                {
                    WriteUnbox(writer, type, value);
                    return;
                }

                if (isdelegateassignment)
                {
                    WriteDelegateAssignment(writer, convertedType, isstaticdelegate, value);
                    return;
                }

//                if (type == null && convertedType == null)
//                {
//                    writer.Write("null");
//                    return;
//                }

                //CTFE

                /* var aVal =  EvaluateValue(value);
                 * if (String.IsNullOrEmpty(aVal))
                 * {
                 *    writer.Write(aVal);
                 * }
                 * else*/
                Core.Write(writer, value);
            }
            else
            {
                writer.Write(TypeProcessor.DefaultValue(declaration.Declaration.Type));
            }
        }
Exemplo n.º 3
0
        private static void ProcessInitializer(OutputWriter writer, LocalDeclarationStatementSyntax declaration,
                                               VariableDeclaratorSyntax variable)
        {
            var initializer = variable.Initializer;

            if (initializer != null)
            {
                if (initializer.Value.CSharpKind() == SyntaxKind.CollectionInitializerExpression)
                {
                    return;
                }

                var value                  = initializer.Value;
                var initializerType        = TypeProcessor.GetTypeInfo(value);
                var memberaccessexpression = value as MemberAccessExpressionSyntax;
                var nameexpression         = value as NameSyntax;
                var nullAssignment         = value.ToFullString().Trim() == "null";
                var shouldBox              = initializerType.Type != null && initializerType.Type.IsValueType &&
                                             !initializerType.ConvertedType.IsValueType;
                var shouldUnBox = initializerType.Type != null && !initializerType.Type.IsValueType &&
                                  initializerType.ConvertedType.IsValueType;
                var isname             = value is NameSyntax;
                var ismemberexpression = value is MemberAccessExpressionSyntax ||
                                         (isname &&
                                          TypeProcessor.GetSymbolInfo(value as NameSyntax).Symbol.Kind ==
                                          SymbolKind.Method);
                var isdelegateassignment = ismemberexpression &&
                                           initializerType.ConvertedType.TypeKind == TypeKind.Delegate;
                var isstaticdelegate = isdelegateassignment &&
                                       ((memberaccessexpression != null &&
                                         TypeProcessor.GetSymbolInfo(memberaccessexpression).Symbol.IsStatic) ||
                                        (isname && TypeProcessor.GetSymbolInfo(nameexpression).Symbol.IsStatic));

                //Do we have an implicit converter, if so, use it
                if (shouldBox || shouldUnBox)
                {
//			        if (shouldUnBox)
//			        {
//			            bool useType = true;
//
//                        //We should start with exact converters and then move to more generic convertors i.e. base class or integers which are implicitly convertible
//			            var correctConverter = initializerType.Type.GetImplicitCoversionOp(initializerType.Type,initializerType.ConvertedType);
////                            initializerType.Type.GetMembers("op_Implicit").OfType<IMethodSymbol>().FirstOrDefault(h => h.ReturnType == initializerType.Type && h.Parameters[0].Type == initializerType.ConvertedType);
//
//			            if (correctConverter == null)
//			            {
//			                useType = false;
//                            correctConverter =
//                            initializerType.ConvertedType.GetImplicitCoversionOp(initializerType.Type, initializerType.ConvertedType); //.GetMembers("op_Implicit").OfType<IMethodSymbol>().FirstOrDefault(h => h.ReturnType == initializerType.Type && h.Parameters[0].Type == initializerType.ConvertedType);
//                        }
//
//			            if (correctConverter != null)
//			            {
//                            if(useType)
//			                writer.Write(TypeProcessor.ConvertType(initializerType.Type) +"."+ "op_Implicit_" + TypeProcessor.ConvertType(correctConverter.ReturnType));
//                            else
//                            {
//			                writer.Write(TypeProcessor.ConvertType(initializerType.ConvertedType) +"."+ "op_Implicit_" + TypeProcessor.ConvertType(correctConverter.ReturnType));
//
//                            }
//                            writer.Write("(");
//                            Core.Write(writer, value);
//                            writer.Write(")");
//                            return;
//                        }
//                    }
//			        if (shouldBox)
                    {
                        bool useType          = true;
                        var  correctConverter =
                            initializerType.Type.GetImplicitCoversionOp(initializerType.ConvertedType,
                                                                        initializerType.Type);
                        //.GetMembers("op_Implicit").OfType<IMethodSymbol>().FirstOrDefault(h => h.ReturnType == initializerType.ConvertedType && h.Parameters[0].Type == initializerType.Type);

                        if (correctConverter == null)
                        {
                            useType          = false;
                            correctConverter =
                                initializerType.ConvertedType.GetImplicitCoversionOp(initializerType.ConvertedType,
                                                                                     initializerType.Type);
                            //.GetMembers("op_Implicit").OfType<IMethodSymbol>().FirstOrDefault(h => h.ReturnType == initializerType.ConvertedType && h.Parameters[0].Type == initializerType.Type);
                        }

                        if (correctConverter != null)
                        {
                            if (useType)
                            {
                                writer.Write(TypeProcessor.ConvertType(initializerType.Type) + "." + "op_Implicit_" +
                                             TypeProcessor.ConvertType(correctConverter.ReturnType));
                            }
                            else
                            {
                                writer.Write(TypeProcessor.ConvertType(initializerType.ConvertedType) + "." +
                                             "op_Implicit_" + TypeProcessor.ConvertType(correctConverter.ReturnType));
                            }
                            writer.Write("(");
                            Core.Write(writer, value);
                            writer.Write(")");
                            return;
                        }
                    }
                }

                if (nullAssignment)
                {
                    writer.Write("null");
                    return;
                }
                if (shouldBox)
                {
                    //Box
                    writer.Write("BOX!(" + TypeProcessor.ConvertType(initializerType.Type) + ")(");
                    //When passing an argument by ref or out, leave off the .Value suffix
                    Core.Write(writer, value);
                    writer.Write(")");
                    return;
                }
                if (shouldUnBox)
                {
                    //UnBox
                    writer.Write("cast!(" + TypeProcessor.ConvertType(initializerType.Type) + ")(");
                    Core.Write(writer, value);
                    writer.Write(")");
                }
                if (isdelegateassignment)
                {
                    var createNew  = !(value is ObjectCreationExpressionSyntax);
                    var typeString = TypeProcessor.ConvertType(initializerType.ConvertedType);

                    if (createNew)
                    {
                        if (initializerType.ConvertedType.TypeKind == TypeKind.TypeParameter)
                        {
                            writer.Write(" __TypeNew!(" + typeString + ")(");
                        }
                        else
                        {
                            writer.Write("new " + typeString + "(");
                        }
                    }

                    var isStatic = isstaticdelegate;
                    if (isStatic)
                    {
                        writer.Write("__ToDelegate(");
                    }
                    writer.Write("&");

                    Core.Write(writer, value);
                    if (isStatic)
                    {
                        writer.Write(")");
                    }

                    if (createNew)
                    {
                        writer.Write(")");
                    }
                    return;
                }
                if (initializerType.Type == null && initializerType.ConvertedType == null)
                {
                    writer.Write("null");
                    return;
                }
                Core.Write(writer, value);
            }
            else
            {
                writer.Write(TypeProcessor.DefaultValue(declaration.Declaration.Type));
            }
        }
Exemplo n.º 4
0
        public static void Go(OutputWriter writer, MemberDeclarationSyntax field, SyntaxTokenList modifiers, string name,
                              TypeSyntax type, EqualsValueClauseSyntax initializerOpt = null, bool isThreadStatic = false)
        {
            writer.WriteIndent();

            var typeinfo = TypeProcessor.GetTypeInfo(type);

//            var isPtr = typeinfo.Type != null && (typeinfo.Type.IsValueType || typeinfo.Type.TypeKind==TypeKind.TypeParameter) ? "" : "";

            var typeStringNoPtr = TypeProcessor.ConvertType(type);

            var typeString = typeStringNoPtr + " ";

            var isConst = IsConst(modifiers, initializerOpt, type);

            var isStatic = isConst;

            //Handle Auto Properties

            // if (modifiers.Any(SyntaxKind.PrivateKeyword)) // Reflection cannot work with this, cant get address or set value
            //   writer.Write("private ");

            if (modifiers.Any(SyntaxKind.PublicKeyword) || modifiers.Any(SyntaxKind.InternalKeyword) ||
                modifiers.Any(SyntaxKind.ProtectedKeyword) || modifiers.Any(SyntaxKind.AbstractKeyword))
            {
                writer.Write("public ");
            }


            if (isThreadStatic)
            {
                writer.Write("static ");
            }

            if (modifiers.Any(SyntaxKind.StaticKeyword) || modifiers.Any(SyntaxKind.ConstKeyword))
            {
                isStatic = true;
                writer.Write("__gshared ");
            }



            if (isConst && typeinfo.Type.IsPrimitive())
            {
                writer.Write("const "); //const has interesting semantics in Dlang
            }

            var         @event = field is EventFieldDeclarationSyntax;
            ITypeSymbol iface;

            ISymbol[] proxies;

            bool isInterface = false;

            // var ename = MemberUtilities.GetMethodName(field, ref isInterface, out iface, out proxies);
            if (@event)
            {
                typeString = ("__Event!(" + typeString + ")");

                if (field.Parent is InterfaceDeclarationSyntax)
                {
                    //writer.Write(typeString);
                    writer.WriteLine(typeString + " " + name + "(" + TypeProcessor.ConvertType(field.Parent) + " __ij)" + "@property;");
                    return;
                }
            }

            writer.Write(typeString);


//                if (isStatic)
//                    writer.Write(typeString);

            writer.Write(name);
            if (isStatic)
            {
//                var fieldInfo = TypeProcessor.GetDeclaredSymbol(field.Parent);
//                if (fieldInfo != null)
//                    writer.Write((!string.IsNullOrEmpty(fieldInfo.ContainingNamespace.FullName())?(fieldInfo.ContainingNamespace.FullName()+".") :"") + fieldInfo.Name+"."+name);
//				writer.Write(name);
            }

            if (!isStatic || isConst)
            {
                if (initializerOpt != null)
                {
                    writer.Write(String.Format(" = cast({0})", typeString));

                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression ||
                        CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
                    {
//                        writer.Write("gc::gc_ptr< " + typeStringNoPtr + " >(");
                        writer.Write(" new " + typeString + " (");
                        var intializer = initializerOpt.Value as InitializerExpressionSyntax;
                        intializer.WriteArrayInitializer(writer, type);

                        writer.Write(")");
                    }

                    else
                    {
                        Core.Write(writer, initializerOpt.Value);
                    }
                }

                else
                {
                    // if (typeinfo.Type.TypeKind != TypeKind.Struct)
                    {
                        writer.Write(" = ");
                        if (typeinfo.Type.TypeKind == TypeKind.Delegate)
                        {
                            writer.Write("new " + typeString + "()");
                        }
                        else
                        {
                            writer.Write(TypeProcessor.DefaultValue(type));
                        }
                    }
                }
            }
            else
            {
                var staticWriter = new TempWriter();

                if (initializerOpt != null)
                {
                    staticWriter.Write(name);

                    staticWriter.Write(" = ");

                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression ||
                        CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
                    {
                        staticWriter.Write("new " + typeStringNoPtr + " (");

                        var intializer = initializerOpt.Value as InitializerExpressionSyntax;

                        intializer.WriteArrayInitializer(staticWriter, type);
                        staticWriter.Write(")");
                    }
                    else
                    {
                        Core.Write(staticWriter, initializerOpt.Value);
                    }

                    staticWriter.Write(";");

                    staticWriter.WriteLine();

                    Context.Instance.StaticInits.Add(staticWriter.ToString());
                }

                else if (typeinfo.Type.TypeKind != TypeKind.Struct)

                {
                    staticWriter.Write(name);
                    staticWriter.Write(" = ");

                    if (typeinfo.Type.TypeKind == TypeKind.Delegate)
                    {
                        staticWriter.Write("new " + typeString + "()");
                    }
                    else
                    {
                        staticWriter.Write(TypeProcessor.DefaultValue(type));
                    }

                    staticWriter.Write(";");

                    staticWriter.WriteLine();

                    Context.Instance.StaticInits.Add(staticWriter.ToString());
                }
            }

            writer.Write(";");
            writer.WriteLine();
        }
        public static void WriteAnonymousType(AnonymousObjectCreationExpressionSyntax syntax)
        {
            var type = TypeProcessor.GetTypeInfo(syntax).Type.As <INamedTypeSymbol>();

            Context.Instance.Type = type;

            TypeProcessor.ClearUsedTypes();

            var mynamespace = Context.Instance.Type.ContainingNamespace.FullName().RemoveFromEndOfString(".Namespace");

            // + "." + TypeState.Instance.TypeName;
            Context.Instance.Namespace = mynamespace;
            var myUsingDirective     = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(mynamespace));
            var SystemUsingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System"));

            // Required as certain functions like boxing are in this namespace

            Context.Instance.UsingDeclarations =
                syntax.Parent.DescendantNodes().OfType <UsingDirectiveSyntax>().ToArray()
                .Union(new[]
            {
                myUsingDirective, SystemUsingDirective
            }).ToArray();

            //using (var writer = new CppWriter (TypeState.Instance.Namespace, )) {

            //Ty

            var anonName = TypeName(type);

            using (var writer = new OutputWriter(Context.Instance.Namespace, StripGeneric(anonName)))
            {
                var fields = type.GetMembers().OfType <IPropertySymbol>().OrderBy(o => o.Name).ToList();

//                writer.WriteLine("namespace anonymoustypes {");
                WriteStandardIncludes.Go(writer);

                writer.WriteIndent();
                writer.Write("class ");
                writer.Write(anonName);

                writer.OpenBrace();

                foreach (var field in fields)
                {
                    writer.WriteIndent();
                    writer.Write("public ");
                    writer.Write(TypeProcessor.ConvertType(field.Type) + " ");
                    writer.Write(WriteIdentifierName.TransformIdentifier(field.Name));
                    writer.Write(" = " + TypeProcessor.DefaultValue(field.Type));
                    writer.Write(";\r\n");
                }

                //Must Write a constructor here ...
                writer.Write("\r\nthis (");
                bool first = true;
                foreach (var field in fields)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(", ");
                    }

                    writer.Write(TypeProcessor.ConvertType(field.Type) + " ");
                    writer.Write("_" + WriteIdentifierName.TransformIdentifier(field.Name));
                }
                writer.Write(")\r\n");
                writer.OpenBrace();
                writer.Indent++;

                foreach (var field in fields)
                {
                    var fieldNAme = WriteIdentifierName.TransformIdentifier(field.Name);

                    writer.WriteLine(fieldNAme + " = _" + fieldNAme + ";");
                }
                writer.Indent--;

                writer.CloseBrace();

                writer.CloseBrace();
//                writer.Write("};");
//                writer.Write("}");
            }
        }
Exemplo n.º 6
0
        public static void Go(OutputWriter writer, MemberDeclarationSyntax field, SyntaxTokenList modifiers, string name,
                              TypeSyntax type, EqualsValueClauseSyntax initializerOpt = null)
        {
            writer.WriteIndent();

            var typeinfo = TypeProcessor.GetTypeInfo(type);

//            var isPtr = typeinfo.Type != null && (typeinfo.Type.IsValueType || typeinfo.Type.TypeKind==TypeKind.TypeParameter) ? "" : "";

            var typeStringNoPtr = TypeProcessor.ConvertType(type);

            var typeString = typeStringNoPtr + " ";

            var isConst = IsConst(modifiers, initializerOpt, type);

            var isStatic = isConst;

            //Handle Auto Properties

            if (modifiers.Any(SyntaxKind.PrivateKeyword))
            {
                writer.Write("private ");
            }

            if (modifiers.Any(SyntaxKind.PublicKeyword) || modifiers.Any(SyntaxKind.InternalKeyword) ||
                modifiers.Any(SyntaxKind.ProtectedKeyword) || modifiers.Any(SyntaxKind.AbstractKeyword))
            {
                writer.Write("public ");
            }

            if (modifiers.Any(SyntaxKind.StaticKeyword) || modifiers.Any(SyntaxKind.ConstKeyword))
            {
                isStatic = true;
                writer.Write("static ");
            }

            if (isConst)
            {
                writer.Write("const ");
//                writer.Write("const ");
            }

            var @event = field is EventFieldDeclarationSyntax;

            if (@event)
            {
                typeString = ("Event!(" + typeString + ")");
            }

            writer.Write(typeString);
//                if (isStatic)
//                    writer.Write(typeString);

            writer.Write(name);
            if (isStatic)
            {
//                var fieldInfo = TypeProcessor.GetDeclaredSymbol(field.Parent);
//                if (fieldInfo != null)
//                    writer.Write((!string.IsNullOrEmpty(fieldInfo.ContainingNamespace.FullName())?(fieldInfo.ContainingNamespace.FullName()+".") :"") + fieldInfo.Name+"."+name);
//				writer.Write(name);
            }

            if (!isStatic || isConst)
            {
                if (initializerOpt != null)
                {
                    writer.Write(" = ");

                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression ||
                        CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
                    {
//                        writer.Write("gc::gc_ptr< " + typeStringNoPtr + " >(");
                        writer.Write(" new " + typeString + " (");
                        var intializer = initializerOpt.Value as InitializerExpressionSyntax;
                        intializer.WriteArrayInitializer(writer, type);

                        writer.Write(")");
                    }

                    else
                    {
                        Core.Write(writer, initializerOpt.Value);
                    }
                }

                else
                {
                    if (typeinfo.Type.TypeKind != TypeKind.Struct)
                    {
                        writer.Write(" = ");
                        if (typeinfo.Type.TypeKind == TypeKind.Delegate)
                        {
                            writer.Write("new " + typeString + "()");
                        }
                        else
                        {
                            writer.Write(TypeProcessor.DefaultValue(type));
                        }
                    }
                }
            }
            else
            {
                var staticWriter = new OutputWriter("", "", false);

                if (initializerOpt != null)
                {
                    staticWriter.Write(name);

                    staticWriter.Write(" = ");

                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression ||
                        CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
                    {
                        staticWriter.Write("new " + typeStringNoPtr + " (");

                        var intializer = initializerOpt.Value as InitializerExpressionSyntax;

                        intializer.WriteArrayInitializer(staticWriter, type);
                        staticWriter.Write(")");
                    }
                    else
                    {
                        Core.Write(staticWriter, initializerOpt.Value);
                    }
//                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression || CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
//                    {
//
//
//						staticWriter.Write("])");
//                    }
                }

                else if (typeinfo.Type.TypeKind != TypeKind.Struct)

                {
                    staticWriter.Write(name);
                    staticWriter.Write(" = ");

                    if (typeinfo.Type.TypeKind == TypeKind.Delegate)
                    {
                        staticWriter.Write("new " + typeString + "()");
                    }
                    else
                    {
                        staticWriter.Write(TypeProcessor.DefaultValue(type));
                    }
                }

//				staticWriter.Write (" SharpNative");

                staticWriter.Write(";");

                staticWriter.WriteLine();

                Context.Instance.StaticInits.Add(staticWriter.ToString());
            }

            writer.Write(";");
            writer.WriteLine();
        }