Exemplo n.º 1
0
 Stream ICodeGenerator.Generate( CodeGeneratorContext context )
 {
     Contract.Requires<ArgumentNullException>( context != null, "context" );
     Contract.Ensures( Contract.Result<Stream>() != null );
     Contract.Ensures( Contract.Result<Stream>().CanRead );
     Contract.Ensures( Contract.Result<Stream>().Position == 0L );
     return null;
 }
Exemplo n.º 2
0
        int IVsSingleFileGenerator.Generate( string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress )
        {
            Debug.Assert( rgbOutputFileContents != null, "rgbOutputFileContents is null" );
            Debug.Assert( rgbOutputFileContents.Length > 0, "rgbOutputFileContents is zero-length" );

            var serviceProvider = site == null ? ServiceProvider.Current : new VisualStudioServiceProvider( (IOleServiceProvider) site );
            var context = new CodeGeneratorContext( wszInputFilePath, bstrInputFileContents, wszDefaultNamespace, new VsProgressAdapter( pGenerateProgress ), serviceProvider );

            try
            {
                // generate content as stream
                using ( var stream = Generate( context ) )
                {
                    var temp = stream as MemoryStream;
                    var size = (int) stream.Length;
                    byte[] buffer;

                    if ( temp == null )
                    {
                        buffer = new byte[size];
                        stream.Read( buffer, 0, size );
                    }
                    else
                    {
                        buffer = temp.ToArray();
                    }

                    rgbOutputFileContents[0] = Marshal.AllocCoTaskMem( size );
                    Marshal.Copy( buffer, 0, rgbOutputFileContents[0], size );
                    pcbOutput = (uint) size;
                }
            }
            catch ( Exception ex )
            {
                rgbOutputFileContents[0] = IntPtr.Zero;
                pcbOutput = 0U;
                context.Progress.ReportError( SR.GenerateError.FormatDefault( ex.Message ) );
                throw;
            }
            finally
            {
                var disposable = serviceProvider as IDisposable;

                if ( disposable != null )
                    disposable.Dispose();
            }

            return 0;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Generates the code content using the provided context.
 /// </summary>
 /// <param name="context">The <see cref="">context</see> used to generate content.</param>
 /// <returns>A <see cref="Stream">stream</see> containing the generated content.</returns>
 protected abstract Stream Generate( CodeGeneratorContext context );