Pattern for executing common code before a property is accessed
<p>Strictly in interest of saving typing in code, I'd like to find some way to append text to members returned by another class. That probably doesn't make sense, so an example. What I'm working on is a class to manage test data:</p>

<pre><code>public class TestFiles
{
    private const string File1RelativePath = @"TestData\File1.xml";
    private const string File2RelativePath = @"TestData\File2.xml";

    private static string RootPath()
    {
        // don't know the deployment location until runtime 
        return Some_DirectoryName_Determined_At_Run_Time_Returned_BySomeOtherModule();
    }

    public static string File1
    {
        get { return Path.Combine(RootPath() + File1RelativePath); }
    }

    public static string File2
    {
        get { return Path.Combine(RootPath() + File2RelativePath); }
    }
}   
</code></pre>

<p>This class does exactly what I want it to, and I can call it simply by : </p>

<pre><code>String FileToUseForTest = TestFiles.File1;
</code></pre>

<p>The problem is that I'm lazy, and when I add more Files I have to do it in 2 places : the constant strings, and the get properties. Maybe I could include the string literal in the getter, but even then I'd have to call Path.Combine(RootPath() ... in each getter, which is far too much work for me. </p>

<p>So, trying another approach, which won't work for reasons shown below:</p>

<pre><code>public class TestFiles
{
    public class FileRelativePaths
    {
        private const string File1RelativePath = @"TestData\File1.xml";
        private const string File2RelativePath = @"TestData\File2.xml";
    }

    private static FileRelativePaths relPaths = new RulePackages();

    FileRelativePaths FullPaths
    {
        get { return relPaths; }
    }

    private static string RootPath()
    {
        // No longer called, but somehow need to find a way to append to paths returned in FullPaths
        return Some_DirectoryName_Determined_At_Run_Time_Returned_BySomeOtherModule();
    }
}   
</code></pre>

<p>This almost works, I get the strong typing and a caller could get the files by </p>

<pre><code>String FileToUseForTest = TestFiles.FullPaths.File1;
</code></pre>

<p>But the problem is that this is giving me the relative paths only, where I really wanted to append some code to the strings returned (by using the method RootPath()).</p>

<p>So, is there any way to get this to work, while still having strong typing and keeping the code length to a minimum? I'm a bit resigned to using the first approach above, but thought I'd ask if there was a creative solution. </p>
