| using System; |
| using System.Collections.Generic; |
| using System.Text; |
| namespace PSNameSpace |
| { |
| class Program |
| { |
| static void Main(string[] args) |
| { |
| PSFactory psFactory = PSFactory.GetInstance(); |
| psFactory.Technique = "Late Binding"; |
| Console.WriteLine("Object created through {0} Technique",psFactory.Technique); |
| Console.ReadLine(); |
| } |
| } |
| public sealed class PSFactory |
| { |
| public string Technique; |
| public PSFactory() |
| { |
| } |
| public static PSFactory GetInstance() |
| { |
| string className = "PSNameSpace.PSFactory"; |
| Object psObject; |
| try |
| { |
| Type t = Type.GetType(className); |
| psObject = Activator.CreateInstance(t); |
| } |
| catch (Exception ex) |
| { |
| throw ex; |
| } |
| return (PSFactory)psObject; |
| } |
| } |
| } |
Monday, 1 July 2013
Simple code to create instance at runtime.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment