Click here to Skip to main content
15,887,359 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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:
C#
public int PropertyName
{
	get
	{
		throw new System.NotImplementedException();
	}
	set
	{
	}
}


This is the desired generated-code:
C#
public int PropertyName
{
	get
	{
		return this.PrivateGetter<int>("PropertyName");
	}
	set
	{
		this.PrivateSetter<int>("PropertyName",value);
	}
}

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

1 solution

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 ? [^]
C#
// '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; }

}
 
Share this answer
 
v2
Comments
Pedro Luis Gil Mora 19-Oct-15 9:39am    
Thing is, I develop for developers, and I would like to do those kinds of thing at design time. They just have to design a partial class and then customize their behaviors into another class file. I like this answer, but I'll roll in the same issue, which is to write the code. I just want to do this when it be an unusual behavior. I mean, this is a default implementation behavior. Thanks a lot friend.
BillWoodruff 19-Oct-15 11:05am    
Hi, If your end-users' hardware don't let you use the later versions of the FrameWork, well, yep, that's a limit. While the .NET Framework actually could handle Property Extensions (F# has them), the C# design team has passed on that, and no sign, as of now, that it will be in the next major release.

Hopefully, someone will respond here with more useful information.
Pedro Luis Gil Mora 19-Oct-15 13:50pm    
Thank you for your advises
Pedro Luis Gil Mora 19-Oct-15 9:52am    
Also, we have clients using Windows XP. Framework 4.5 could not be an option due it's not supported.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900