Advertisement
ivandrofly

Partial Class vs Interface

Apr 18th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using PartialProject.objects;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Interface classObj = new Class();
  15.             //
  16.             Interface obj = classObj.Instance;
  17.             Console.ReadLine();
  18.         }
  19.     }
  20. }
  21.  
  22. namespace PartialProject.objects
  23. {
  24.     public interface Interface
  25.     {
  26.         Interface Instance { get; }
  27.     }
  28.  
  29.     //To make sure the autogenerated code inherits Interface
  30.     public partial class Class : Interface
  31.     {
  32.         Interface Interface.Instance
  33.         {
  34.             get
  35.             {
  36.                 return Instance;
  37.             }
  38.         }
  39.     }
  40.  
  41.     //This is autogenerated
  42.     public partial class Class
  43.     {
  44.         private Class Instance
  45.         {
  46.             get
  47.             {
  48.                 return this;
  49.             }
  50.         }
  51.     }
  52. }
  53.  
  54. // Source: http://stackoverflow.com/questions/2606461/problem-with-interface-implementation-in-partial-classes
  55. // Note: Fixed stackoverflow issue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement