예제 #1
0
        /// <summary>
        /// Creates files with VS sync
        /// </summary>
        public static TemplateFileManager Create(object textTransformation)
        {
            DynamicTextTransformation2 transformation = DynamicTextTransformation2.Create(textTransformation);
            IDynamicHost2 host = transformation.Host;

            return(new TemplateFileManager(transformation));
        }
예제 #2
0
        /// <summary>
        /// Initializes an TemplateFileManager Instance  with the
        /// TextTransformation (T4 generated class) that is currently running
        /// </summary>
        private TemplateFileManager(object textTransformation)
        {
            if (textTransformation == null)
            {
                throw new ArgumentNullException("textTransformation");
            }

            _textTransformation    = DynamicTextTransformation2.Create(textTransformation);
            _generationEnvironment = _textTransformation.GenerationEnvironment;

            var hostServiceProvider = _textTransformation.Host.AsIServiceProvider();

            if (hostServiceProvider == null)
            {
                throw new ArgumentNullException("Could not obtain hostServiceProvider");
            }

            dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
            if (dte == null)
            {
                throw new ArgumentNullException("Could not obtain DTE from host");
            }

            this.templateProjectItem     = dte.Solution.FindProjectItem(_textTransformation.Host.TemplateFile);
            this.CanOverrideExistingFile = true;
            this.IsAutoIndentEnabled     = false;
            this.Encoding     = System.Text.Encoding.UTF8;
            checkOutAction    = fileName => dte.SourceControl.CheckOutItem(fileName);
            projectSyncAction = keepFileNames => ProjectSync(templateProjectItem, keepFileNames);
        }
예제 #3
0
        /// <summary>
        /// Creates an instance of the DynamicTextTransformation class around the passed in
        /// TextTransformation shapped instance passed in, or if the passed in instance
        /// already is a DynamicTextTransformation, it casts it and sends it back.
        /// </summary>
        public static DynamicTextTransformation2 Create(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            DynamicTextTransformation2 textTransformation = instance as DynamicTextTransformation2;

            if (textTransformation != null)
            {
                return(textTransformation);
            }

            return(new DynamicTextTransformation2(instance));
        }