Exemplo n.º 1
0
        public JsBlockStatement CreateDefaultConstructor(BaseTypeDeclarationSyntax type)
        {
            var classType = transformer.model.GetDeclaredSymbol(type);

            var fullTypeName = type.GetFullName();
            var constructorBlock = new JsBlockStatement();

            if (fullTypeName != "System.Object")
            {
                constructorBlock.Express(InvokeParameterlessBaseClassConstructor(classType.BaseType));
            }

            if (type is ClassDeclarationSyntax)
            {
                constructorBlock.Aggregate(InitializeInstanceFields((ClassDeclarationSyntax)type));
            }

            var block = new JsBlockStatement();
            var constructorName = classType.GetDefaultConstructorName();
            block.Add(StoreInPrototype(constructorName, Js.Reference(SpecialNames.DefineConstructor).Invoke(
                Js.Reference(SpecialNames.TypeInitializerTypeFunction), 
                Js.Function().Body(constructorBlock))));

            return block;            
        }