Ejemplo n.º 1
0
        private static bool ExecuteTransaction([NotNull] IPsiModule module, [NotNull] Action action)
        {
            PsiManager psiManager = PsiManager.GetInstance(module.GetSolution());

            if (psiManager.HasActiveTransaction)
            {
                action();
                return(true);
            }
            return(psiManager.DoTransaction(action, "T4 Assembly Reference").Succeded);
        }
Ejemplo n.º 2
0
        private bool ReferenceModuleImpl([NotNull] IPsiModule module, [NotNull] IPsiModule moduleToReference, [CanBeNull] string ns)
        {
            if (!CanReferenceModule(module, moduleToReference))
            {
                return(false);
            }

            var t4PsiModule = (T4PsiModule)module;
            var assembly    = (IAssembly)moduleToReference.ContainingProjectModule;

            Assertion.AssertNotNull(assembly, "assembly != null");

            var t4File = t4PsiModule.SourceFile.GetNonInjectedPsiFile <T4Language>() as IT4File;

            if (t4File == null)
            {
                return(false);
            }

            Action action = () => {
                // add assembly directive
                AddDirective(t4File, _directiveInfoManager.Assembly.CreateDirective(assembly.FullAssemblyName));

                // add import directive if necessary
                if (!String.IsNullOrEmpty(ns) &&
                    !t4File.GetDirectives(_directiveInfoManager.Import).Any(d => String.Equals(ns, d.GetAttributeValue(_directiveInfoManager.Import.NamespaceAttribute.Name), StringComparison.Ordinal)))
                {
                    AddDirective(t4File, _directiveInfoManager.Import.CreateDirective(ns));
                }
            };

            PsiManager psiManager = PsiManager.GetInstance(module.GetSolution());

            if (psiManager.HasActiveTransaction)
            {
                action();
                return(true);
            }
            return(psiManager.DoTransaction(action, "T4 Assembly Reference").Succeded);
        }