使用类图与自定义工具模板 [英] Using class diagram with custom tool template

查看:83
本文介绍了使用类图与自定义工具模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题之后,我决定使用T4正如@BillWoodruff告诉我的,但我发现自己有一个限制:我不知道如何通过Visual Studio - 类图设计器覆盖同一个生成的类的属性实现,这允许我使用自定义工具模板。我的意思是,如何读取类图,无论它做什么,然后我将覆盖生成的实现。在此先感谢。

这是生成的属性实现:

After this question, I decided to use T4, as @BillWoodruff told me, but I found to myself a limitation: I don't know how to overwrite a property implementation at the same generated class by Visual Studio - Class Diagram Designer, which allows me to use a custom tool template. I mean, how to read the class diagram, whatever it does, then I'll overwrite the generated implementation. Thanks in advance.
This is the generated property implemetation:

public int PropertyName
{
	get
	{
		throw new System.NotImplementedException();
	}
	set
	{
	}
}





这是所需的生成代码:



This is the desired generated-code:

public int PropertyName
{
	get
	{
		return this.PrivateGetter<int>("PropertyName");
	}
	set
	{
		this.PrivateSetter<int>("PropertyName",value);
	}
}



PD :(请原谅我的英文,我是古巴人)


PD:(Excuse my english, I'm cuban)

推荐答案

佩德罗,我希望我已经深入到T4,我可以帮助你;如果你在几天内没有得到有用的答复,我建议你在StackOverFlow上发布这个。



您可以探索System.Dynamic命名空间以进行后期绑定资源......如果这就是你想要在这里实现的目标。



你是否知道C#5.0,.NET 4.5,4.6的CallerMemberName功能,它可以您是否无需使用硬编码字符串来传输属性的名称? [ ^ ]
Hi, Pedro, I wish I had gone deep enough into T4 that I could help you here; if you do not get a useful reply here in a few days, I suggest you post this on StackOverFlow.

You could explore the System.Dynamic namespace for late-binding resources ... if that is what you are trying to achieve here.

Are you aware of the CallerMemberName feature of C# 5.0, .NET 4.5, 4.6, which can eliminate the need for you to use hard-coded strings to transmit the name of a Property ? [^]
// 'CallerMemberName use example:

// required: .NET >= 4.5
using System.Runtime.CompilerServices;

public bool SomeFunc(int oldvalue, int newvalue, [CallerMemberName] string pname = null)
{
    Console.WriteLine("Current Value: {0} New Value: {1} FromProperty: {2}", oldvalue, newvalue, pname);

    return oldvalue != newvalue;
}

private int _myintprop;

public int MyIntProp
{
    set { if (SomeFunc(_myintprop, value)) _myintprop = value; }

    get { return _myintprop; }

}


这篇关于使用类图与自定义工具模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆