Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Preventng direct creation of sub-class instances
Message
From
28/07/2006 11:56:57
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01141060
Message ID:
01141190
Views:
22
>Do protected constructors; later one you might want to inherit from a subclass.
>The Activator.CreateInistance should not work if for protected/private constructors.So you can refactor the CreateInstance method into an generic interface which returns the and implementit as static.

Vlad,
Actiavtor is working:
using System;
using System.Reflection;

namespace Test
{
    public class MyObject
    {
        private MyObject() { Console.WriteLine("Object created");}

        public static MyObject NewMyObject()
        {
            return new MyObject();
        }
    }
    class Tester
    {
        static void Main(string[] args)
        {
             Test.MyObject mo = 
           (Test.MyObject)Activator.CreateInstance(typeof(Test.MyObject),true);
        }
    }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform