- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 VS2012 设计 UML 图,使用 T4 生成自定义类和接口(interface)。
我使用 TFS 作为源代码管理器。
但是从昨天开始我收到一个错误并且没有生成代码。
5/13/2013 8:18:59 AM: Code generation or text transformation started.
5/13/2013 8:19:51 AM: Errors encountered in 'ClassTemplate.t4' while generating code for 'Andish.CSS.Modeling.UMLDiagram::Model::Andish.CSS.Domain::BusinessDomain::Calculator::Grou pPreCalculatingResult' - (Class).
5/13/2013 8:19:58 AM: Code generation complete. Errors: 1. Warnings: 0.
5/13/2013 8:19:58 AM: Unable to write log file: F:\Andish\AndishmandFramWork\Modeling\Andish.CSS.Modeling.UMLDiagram\CodeGeneration.Log.xml - Access to the path 'F:\Andish\AndishmandFramWork\Modeling\Andish.CSS.Modeling.UMLDiagram\CodeGeneration.Log.xm l' is denied.
这是我的 VS2012 图片
我得到一个错误,比如 down :
Error 44 Errors were generated when initializing the transformation object. The transformation will not be run. The following Exception was thrown:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplating5DC31BF3C568533E6A5135685CF1D48CEE628C2D066E9F2E28996B 26FB846E02D5A1B9165E6B13EEEEA7BBA99E06465E913189341F3D59CE816F2CEB52FAEBA8.GeneratedTextTra nsformation.AppliesToElement()
at Microsoft.VisualStudio.ArchitectureTools.TextTransformation.ModelingTextTransformation.Init ialize()
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0)
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation()
我使用 t4 类 down
<#@ Include File="TemplateHeader.t4" #>
<#@ Modeling ElementType="Microsoft.VisualStudio.Uml.Classes.IClass" Processor="ModelingProcessor" ApplyStereotypes="CSharp" #>
<#@ Import Namespace="Microsoft.VisualStudio.Uml.AuxiliaryConstructs" #>
<#@ Import Namespace="Microsoft.VisualStudio.Uml.Classes" #>
<#@ Import Namespace="Microsoft.VisualStudio.ArchitectureTools.Extensibility.Uml" #>
<#@ Include File="CSharpCommentHelpers.t4" #>
<#@ Include File="CSharpHelpers.t4" #>
<#@ Output Extension=".cs" #>
<#
WriteAutoGeneratedWarningHeader();
WriteLine("using System.Runtime.Serialization;");
WriteLine("using System.ServiceModel;");
string classNamespace = GetNamespace(this.Element.Namespace);
if(!string.IsNullOrEmpty(classNamespace))
{
#>
namespace <#= classNamespace #>
{
<#
PushIndent("\t");
}
WriteUsingStatements(this.Element);
WriteLine("");
System.Globalization.PersianCalendar PDate=new System.Globalization.PersianCalendar();
DateTime BeforDate=new DateTime(PDate.GetYear(System.DateTime.Now),PDate.GetMonth(System.DateTime.Now),PDate.GetDayOfMonth(System.DateTime.Now),PDate.GetHour(System.DateTime.Now),PDate.GetMinute(System.DateTime.Now),PDate.GetSecond(System.DateTime.Now));
string Date=String.Format("{0:yyyy/MM/dd HH:mm:ss}",BeforDate);
WriteSinglelineDocComment("Author","Name = \"T4Generator\"","");
WriteSinglelineDocComment("CreateDate","Date = \"" + Date+"\"","");
WriteSinglelineDocComment("LastModifyUser","Name = \"T4Generator\"","");
WriteSinglelineDocComment("LastModifyDate","Date = \"" + Date+"\"","");
WriteSinglelineDocComment("Version","Number = \"1\"","");
WriteSinglelineDocComment("Release","Number = \"1\"","");
WriteSummaryComment(this.Element.Description);
WriteTemplateTypeParameterComments(TemplateParameterNameDescriptionPairs(this.Element));
//WriteLine("[ServiceErrorBehaviour(typeof(HttpErrorHandler))]");
foreach(var comment in this.Element.GetModelStore().AllInstances<IComment>().Where(c => c.AnnotatedElements.Contains(this.Element)))
{
WriteRemarksComment(comment.Body);
}
#>
<#
WriteClassClrAttributes(this.Element);
#>
<#= ClassVisibility(this.Element) #><#= ClassUnsafeOption(this.Element) #><#= ClassStaticOption(this.Element) #><#= ClassAbstractOption(this.Element) #><#= ClassSealedOption(this.Element) #><#= ClassPartialOption(this.Element) #>class <#= ClassifierName(this.Element) #><#= ImplementedAndInheritedList(this.Element) #><# WriteClassifierConstraintOption(this.Element); #>
{
<#
PushIndent("\t");
// Write Attributes
var ownedAttributes = this.Element.OwnedAttributes;
foreach(IProperty attribute in ownedAttributes)
{
WriteSummaryComment(attribute.Description);
WriteClassUmlPropertyDefinition(attribute);
WriteLine("");
}
#>
<#
// Write Associations
var navigableOwnedEnds = GetNavigableOwnedEnds(this.Element, ownedAttributes);
foreach(IProperty ownedEnd in navigableOwnedEnds)
{
WriteSummaryComment(ownedEnd.OwningAssociation.Description);
WriteSummaryComment(ownedEnd.Description);
WriteClassUmlPropertyDefinition(ownedEnd);
WriteLine("");
}
#>
<#
// Write Operations
foreach(IOperation operation in this.Element.OwnedOperations)
{
WriteSinglelineDocComment("Author","Name = \"T4Generator\"","");
WriteSinglelineDocComment("CreateDate","Date = \"" + Date+"\"","");
WriteSinglelineDocComment("LastModifyUser","Name = \"T4Generator\"","");
WriteSinglelineDocComment("LastModifyDate","Date = \"" + Date+"\"","");
WriteSinglelineDocComment("Version","Number = \"1\"","");
WriteSinglelineDocComment("Release ","Number = \"1\"","");
WriteSummaryComment(operation.Description + GetCommentOfGlobalMethod(operation.Name));
foreach (IParameter parameter in operation.OwnedParameters.Where(p => p.Direction != ParameterDirectionKind.Return))
{
WriteParameterComment(parameter.Name, parameter.Description);
}
WriteSinglelineDocComment("returns","","");
if(GetStereotype(operation) == "method")
{
WriteMethodClrAttributes(operation);
if(IsConstructor(operation) || IsDestructor(operation))
{
#>
<#= MethodVisibility(operation) #><#= operation.Name #>(<# WriteMethodParameterList(operation); #>)
{
}
<#
}
else
{
#>
<#= MethodVisibility(operation) #><#= MethodUnsafeOption(operation) #><#= OperationStaticOption(operation) #><#= ClassMethodOverloadOption(operation, this.Element) #><#= MethodPartialOption(operation) #><#= MethodType(operation) #> <#= operation.Name #>(<# WriteMethodParameterList(operation); #>)<# WriteClassMethodBody(operation); #>
<#
}
WriteLine("");
}
else if(GetStereotype(operation) == "indexer")
{
WriteIndexerClrAttributes(operation);
#>
<#= IndexerVisibility(operation) #><#= IndexerUnsafeOption(operation) #><#= OperationStaticOption(operation) #><#= ClassIndexerOverloadOption(operation, this.Element) #><#= IndexerType(operation) #> this[<# WriteIndexerParameterList(operation); #>]
{
<#
PushIndent("\t");
#>
<#= IndexerGetVisibility(operation) #>get<# WriteClassIndexerAccessorBody(operation); #>
<#= IndexerSetVisibility(operation) #>set<# WriteClassIndexerAccessorBody(operation); #>
<#
PopIndent();
#>
}
<#
WriteLine("");
}
}
PopIndent();
#>
}
<#
ClearIndent();
if(!string.IsNullOrEmpty(classNamespace))
{
#>
}
<# } #>
<#+
#region Inheritance
/// <summary>
/// Gets the implemented and inherited types of the given class.
/// </summary>
/// <param name="aClass">The given class</param>
/// <returns>implementedAndInherted types</returns>
private static string ImplementedAndInheritedList(IClass aClass)
{
var list = ImplementedAndInheritedTypes(aClass);
if(list.Any())
{
return " : " + string.Join(", ", list.Select(t => ElementType(t)));
}
else
{
return string.Empty;
}
}
#endregion Inheritance
#region Polymorphism
/// <summary>
/// Gets the overload option of the indexer.
/// </summary>
/// <param name="operation">The operation</param>
/// <param name="owner">The class</param>
/// <returns>The overload option for the operation</returns>
private static string ClassIndexerOverloadOption(IOperation operation, IClass owner)
{
return ClassOperationOverloadOption(operation, owner);
}
/// <summary>
/// Gets the overload option of the method.
/// </summary>
/// <param name="operation">The operation</param>
/// <param name="owner">The class</param>
/// <returns>The overload option for the operation</returns>
private static string ClassMethodOverloadOption(IOperation operation, IClass owner)
{
if(string.IsNullOrEmpty(MethodPartialOption(operation)))
{
return ClassOperationOverloadOption(operation, owner);
}
else
{
return string.Empty;
}
}
/// <summary>
/// Gets the overload option of the operation.
/// </summary>
/// <param name="operation">The operation</param>
/// <param name="owner">The class</param>
/// <returns>The overload option for the operation</returns>
private static string ClassOperationOverloadOption(IOperation operation, IClass owner)
{
string overload = string.Empty;
if(!string.IsNullOrEmpty(OperationAbstractOption(operation)))
{
overload += "abstract ";
}
else if(IsInheritedMember(operation, owner))
{
overload += "override ";
if(!string.IsNullOrEmpty(OperationSealedOption(operation)))
{
overload += "sealed ";
}
}
//دلیل کامنت شدن حذف کلمه virctual از تعریف متد
// else if(IsOverridable(operation, owner))
// {
// overload += "virtual ";
// }
return overload;
}
/// <summary>
/// Gets the overload option of the property.
/// </summary>
/// <param name="property">The property</param>
/// <param name="owner">The class</param>
/// <returns>The overload option for the property</returns>
private static string ClassPropertyOverloadOption(IProperty property, IClass owner)
{
string overload = string.Empty;
if(IsInheritedMember(property, owner))
{
overload = "override ";
if(!string.IsNullOrEmpty(PropertySealedOption(property)))
{
overload += "sealed ";
}
}
else if(IsOverridable(property, owner))
{
overload += "virtual ";
}
return overload;
}
/// <summary>
/// Checks if the operation is overridable.
/// </summary>
/// <param name="operation">The operation</param>
/// <param name="owner">The class</param>
/// <returns>true if the operation is an inherited member.</returns>
private static bool IsOverridable(IOperation operation, IClass owner)
{
bool isPrivate = MethodVisibility(operation) == "private " || IndexerVisibility(operation) == "private ";
return !isPrivate && string.IsNullOrEmpty(OperationStaticOption(operation)) && string.IsNullOrEmpty(OperationSealedOption(operation)) && HasVirtualMembers(owner);
}
/// <summary>
/// Checks if the property is overridable.
/// </summary>
/// <param name="property">The property</param>
/// <param name="owner">The class</param>
/// <returns>true if the property is an inherited member.</returns>
private static bool IsOverridable(IProperty property, IClass owner)
{
bool isPrivate = FieldVisibility(property) == "private " || PropertyVisibility(property) == "private ";
return !isPrivate && string.IsNullOrEmpty(AttributeStaticOption(property)) && string.IsNullOrEmpty(PropertySealedOption(property)) && HasVirtualMembers(owner);
}
/// <summary>
/// Checks if the classifier could have virtual memebers.
/// </summary>
/// <param name="aClass">The class</param>
/// <returns>true if the property is an inherited member.</returns>
private static bool HasVirtualMembers(IClass aClass)
{
return string.IsNullOrEmpty(ClassSealedOption(aClass)) && string.IsNullOrEmpty(ClassStaticOption(aClass));
}
/// <summary>
/// Checks if the property is an inherited member.
/// </summary>
/// <param name="property">The property</param>
/// <param name="owner">The owner class of the property</param>
/// <returns>true if the property is an inherited member.</returns>
private static bool IsInheritedMember(IProperty property, IClass owner)
{
var types = ImplementedOrInheritedTypes(owner);
foreach(IType type in types)
{
IClassifier baseClassifier = type as IClassifier;
if(baseClassifier != null)
{
ITemplateBinding templateBinding = GetTemplateBinding(baseClassifier);
IClassifier bindingClassifier = GetBindingClassifier(templateBinding);
if(bindingClassifier != null)
{
baseClassifier = bindingClassifier;
}
foreach(IProperty propertyInBase in GetOwnedProperties(baseClassifier))
{
bool isInheritedMember = IsInheritedMember(propertyInBase, property, templateBinding);
if(isInheritedMember)
{
return true;
}
}
}
}
return false;
}
/// <summary>
/// Checks if the property is an inherited member.
/// </summary>
/// <param name="propertyInBase">The property in base</param>
/// <param name="propertyInSubClass">The property in subclass</param>
/// <param name="templateBinding">The template binding</param>
/// <returns>true if the property in the subclass is an inherited member; false if it is not or the base is an interface</returns>
private static bool IsInheritedMember(IProperty propertyInBase, IProperty propertyInSubClass, ITemplateBinding templateBinding)
{
var propertyInBaseOwner = propertyInBase.Owner;
if(propertyInBaseOwner is IAssociation)
{
propertyInBaseOwner = ((IAssociation)propertyInBaseOwner).SourceElement;
}
if(propertyInBaseOwner is IInterface)
{
return false;
}
else if(propertyInBaseOwner is IClass)
{
bool isInheritedProperty = IsInheritedProperty(propertyInSubClass, propertyInBase, templateBinding);
bool isOverridable = IsOverridable(propertyInBase, (IClass)propertyInBaseOwner);
return isInheritedProperty && isOverridable;
}
return false;
}
/// <summary>
/// Checks if the operation is an inherited member.
/// </summary>
/// <param name="operation">The operation</param>
/// <param name="owner">The owning class of the operation</param>
/// <returns>true if the operation is an inherited member.</returns>
private static bool IsInheritedMember(IOperation operation, IClass owner)
{
var types = ImplementedOrInheritedTypes(owner);
foreach(IType type in types)
{
IClassifier baseClassifier = type as IClassifier;
if(baseClassifier != null)
{
ITemplateBinding templateBinding = GetTemplateBinding(baseClassifier);
IClassifier bindingClassifier = GetBindingClassifier(templateBinding);
if(bindingClassifier != null)
{
baseClassifier = bindingClassifier;
}
foreach(IOperation operationInBase in GetOwnedOperations(baseClassifier))
{
bool isInheritedMember = IsInheritedMember(operationInBase, operation, templateBinding);
if(isInheritedMember)
{
return true;
}
}
}
}
return false;
}
/// <summary>
/// Checks if the operation is an inherited member.
/// </summary>
/// <param name="operationInBase">The operation in base</param>
/// <param name="operationInSubClass">The operation in the subclass</param>
/// <param name="templateBinding">The template binding</param>
/// <returns>true if the operation in the subclass is an inherited member; false if it is not or the base is an interface</returns>
private static bool IsInheritedMember(IOperation operationInBase, IOperation operationInSubClass, ITemplateBinding templateBinding)
{
var operationInBaseOwner = operationInBase.Owner;
if(operationInBaseOwner is IAssociation)
{
operationInBaseOwner = ((IAssociation)operationInBaseOwner).SourceElement;
}
if(operationInBaseOwner is IInterface)
{
return false;
}
else if(operationInBaseOwner is IClass)
{
bool isInheritedOperation = IsInheritedOperation(operationInSubClass, operationInBase, templateBinding);
bool isOverridable = IsOverridable(operationInBase, (IClass)operationInBaseOwner);
return isInheritedOperation && isOverridable;
}
return false;
}
/// <summary>
/// Checks if the operation in subclass is inherited from the operation in base.
/// </summary>
/// <param name="operationInSubClass">The operation in subClass</param>
/// <param name="operationInBase">The operation in base</param>
/// <param name="templateBinding">The template binding</param>
/// <returns>if operation in subClass is inherited from the operation in base.</returns>
private static bool IsInheritedOperation(IOperation operationInSubClass, IOperation operationInBase, ITemplateBinding templateBinding)
{
if(templateBinding == null)
{
return operationInSubClass.Signature == operationInBase.Signature;
}
if(operationInSubClass.Name != operationInBase.Name)
{
return false;
}
var subClassOperationOwnedParametersInOrder = GetOwnedParametersInOrder(operationInSubClass);
var baseClassOperationOwnedParametersInOrder = GetOwnedParametersInOrder(operationInBase);
int numOfSubClassOperationOwnedParameters = subClassOperationOwnedParametersInOrder.Count();
if(numOfSubClassOperationOwnedParameters != baseClassOperationOwnedParametersInOrder.Count())
{
return false;
}
var parameterSubstitutions = templateBinding.ParameterSubstitutions;
// find the newly defined template parameters
var baseClassifier = (IClassifier)operationInBase.Owner;
var subClassifier = (IClassifier)operationInSubClass.Owner;
var subClassNewlyDefinedTemplateParameterNames = GetNewlyDefinedTemplateParameterNamesInSubClass(baseClassifier, subClassifier, parameterSubstitutions);
for(int i=0; i < numOfSubClassOperationOwnedParameters; i++)
{
var subClassOperationOwnedParameter = subClassOperationOwnedParametersInOrder.ElementAt(i);
var baseClassOperationOwnedParameter = baseClassOperationOwnedParametersInOrder.ElementAt(i);
if(subClassOperationOwnedParameter.Direction != baseClassOperationOwnedParameter.Direction)
{
return false;
}
bool isParameterInBaseEnumerable = IsEnumerable(baseClassOperationOwnedParameter);
bool isParameterInSubClassEnumerable = IsEnumerable(subClassOperationOwnedParameter);
if(isParameterInBaseEnumerable != isParameterInSubClassEnumerable)
{
return false;
}
if(!OneTypeOverridesTheOther(baseClassOperationOwnedParameter.Type, subClassOperationOwnedParameter.Type, parameterSubstitutions, subClassNewlyDefinedTemplateParameterNames))
{
return false;
}
}
return true;
}
/// <summary>
/// Gets the owned parameters in order: first is the parameter of return type, and then the rest of the parameters.
/// </summary>
/// <param name="operation">The operation</param>
/// <returns>List of owned parameters in order</returns>
private static List<IParameter> GetOwnedParametersInOrder(IOperation operation)
{
var orderedSet = Enumerable.Union<IParameter>(operation.OwnedParameters.Where(parameter => parameter.Direction == ParameterDirectionKind.Return), operation.OwnedParameters.Where(parameter => parameter.Direction != ParameterDirectionKind.Return));
return orderedSet.ToList();
}
/// <summary>
/// Checks if the two type names are equal with considering of the template binding substitutions.
/// </summary>
/// <param name="propertyInSubClass">The property in subClass</param>
/// <param name="propertyInBase">The property in base</param>
/// <param name="templateBinding">The template binding</param>
/// <returns>if property in subClass is inherited from the property in base.</returns>
.........
我不能复制T4模板的所有代码,因为这篇文章的最大长度是30000 carachter。
最佳答案
错误消息说访问“F:\Andish\AndishmandFramWork\Modeling\Andish.CSS.Modeling.UMLDiagram\CodeGeneration.Log.xm l”被拒绝。
可能文件被 TFS 锁定了。尝试在生成之前 checkout 文件。
关于c# - 使用 T4 生成 Visual Studio 2012 体系结构代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514919/
我经常使用 SSMS 查询数据和构建数据集,我的 IT 部门负责数据库管理。 最近我发现了 Azure Data Studio,我喜欢: 智能感知 源代码控制(例如使用 Git) 来自社区的扩展 SQ
我想根据我使用的 visual studio 版本编译不同的东西,比如 #if VISUAL_STUDIO_VERSION > 2015 eventH?.Invoke(this, EventArgs.
我们的开发团队计划从 visual studio 2005 升级到 visual studio 2010 -- 跳过 visual studio 2008。 大部分项目是VB ASP.NET项目,使用
我的Visual Studio 2015无法构建2010平台工具集。它说: The build tools for Visual Studio 2010 (v100) cannot be found.
我目前正在使用 Visual Studio 2015 来编程 ASP.NET Core 应用程序。我对安装 Visual Studio 2017 有以下疑问: 什么被认为是最佳实践和/或最干净的方法?
尝试从扩展和更新获取 Visual Studio 扩展时,出现以下错误:- 向 visualstudiogallery.msdn.microsoft.com/Services/VStudio/Exte
这个问题在这里已经有了答案: Can Visual Studio Code and VS 2012 be installed on same computer? (1 个回答) 关闭去年。 在安装了
作为标准安装的一部分,Visual Studio Code 带有一个名为“Monokai Dimmed”的颜色主题。 有没有办法将它移植到 Visual Studio 2015?我检查了社区主题( h
我想开始编程 CUDA。 我已经安装了 Visual Studio 2010 Express。 我还安装了 nVidia nSight Visual Studio。 而且我具备所有常见的先决条件(Ne
Visual Studio Community Edition是否可以使用Visual Studio Online帐户上的存储库? 我一直为包含在Online帐户中的Visual Studio Onl
我有一个我一直在开发的应用程序,但在 android studio 上遇到了问题。当我点击“build->run”然后选择我的设备时,应用程序永远不会在我的手机上运行(并且自动出现的android-s
我正在使用Visual Studio2010。我面临的一个问题是,当我创建一个新的Web项目时,Visual Studio将创建该项目,并且不会在解决方案资源管理器中显示其解决方案。 另一件事是,我想
我通读了这里的许多帖子,却找不到一个有效的明确答案。因此,在花了一些时间使它生效之后,我认为应该发布它。 问题:发布配置文件将建立在服务器上,但不会发布。 解: 确保已安装Microsoft Wind
我正在尝试使用Visual Studio 2012构建针对.NET 3.5的C++ CLI应用程序。 通过安装Visual Studio 2008,并指定v90平台工具集,我已经在一台机器上进行了这项
我在 Microsoft Visual Studios 2013 中有一个项目,我想在 Microsoft Visual Studios 2010 中打开它。有什么简单的方法吗?还是我必须在2010年
我想知道,如果我发送一个解决方案文件夹(它是用 visual studio C# 编写的),您可以在 visual studio for mac 中打开解决方案吗? 在visual studio 20
有没有办法在 Visual Studio Code 和 Visual Studio 中设置相同的快捷方式(而不必每次都手动更改它们)? 例如,我在 Visual Studio Code 中经常使用 A
我刚开始了解 Visual Studio Code。我想知道,我可以将 Visual Studio 替换为所有 .NET 开发相关的工作吗? 我可以节省 Visual Studio 许可的成本吗? V
我安装了具有有效许可证(Visual Studio 订阅)的 Visual Studio 2019 企业版(VS 2019 16.1.4),它运行良好。 突然之间,当我尝试打开项目或项目中的任何文件时
我一直在使用 Compass 编译 Windows 环境中的 sass 文件,无论是在命令行上还是使用 Compass-app 来查看目录。 我刚刚开始使用 Visual Studio(专业版 201
我是一名优秀的程序员,十分优秀!