title: Detect c# version at compile time
body: <p>I have an old line of c# code that looks basically like this:</p>
  
  <pre><code>foo.set_Parent(parent);
  </code></pre>
  
  <p>It has compiled fine for years. Now in VS2015 I get the error:</p>
  
  <blockquote>
    <p>CS0571    'Foo.Parent.set': cannot explicitly call operator or accessor</p>
  </blockquote>
  
  <p>So I can rewrite the line as:</p>
  
  <pre><code>foo.Parent=parent;
  </code></pre>
  
  <p>This builds fine in VS2015, but in VS2013 it gives the error:</p>
  
  <blockquote>
    <p>'Foo.Parent' is not supported by the language; try directly calling
    accessor methods 'Foo.get_Parent()' or Foo.set_Parent(Foo)'</p>
  </blockquote>
  
  <p>So the simple fix is to simply ifdef these two lines based upon which version of the compiler is running. But how do you detect which version of the compiler is executing?</p>
  
  <p>And for the record, no, I can't just dictate that everyone on the team simultaneously upgrades to VS2015.</p>
  
  <p><strong>Additional info -</strong>
  For everyone smelling a rat, I'll go ahead and drag out the ugly truth, although I don't think it will change much of anything. The class Foo is from an ancient Borland assembly that is all bound up in Delphi (and yes, we're migrating away but not there yet). So the actual code, that compiles up to VS2013, looks like this:</p>
  
  <pre><code>using Borland.Vcl;
  using RepGen;
  using SnapReportsForm;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.InteropServices;
  
  namespace MigrantCOM {
     [ComVisible(true)]
     [Guid("48245BA3-736B-4F98-BDC5-AD86F77E39F4")]
     [ProgId("MigrantCOM.Exports")]
     [ClassInterface(ClassInterfaceType.AutoDual)]
            public class MigrantCLRExports {   // : MarshalByRefObject 
        public string Test(string s) { return s+s; }
     }
  
     [ComVisible(true)]
     [Guid("1154D364-B588-4C31-88B9-141072303117")]
     [ProgId("MigrantCOM.SnapRepCOM")]
     [ClassInterface(ClassInterfaceType.AutoDual)]
     public class SnapRepCOM {
        TRepGen repGen;
        TStringList snapRefs=new TStringList();
        TForm parent=new TForm(null);
        TMemo designerMemo;
        List&lt;TReference&gt; references=new List&lt;TReference&gt;();
        TRunAsSnapContext runAsSnapContext=new TRunAsSnapContext();
  
        public SnapRepCOM() {
           designerMemo=new TMemo(parent); designerMemo.set_Parent(parent);
           ...
        }
  </code></pre>
  
  <p>So the class being instantiated is Borland.Vcl.TMemo which is part of the old Delphi assembly.</p>