Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Preventng direct creation of sub-class instances
Message
De
28/07/2006 11:56:57
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01141060
Message ID:
01141190
Vues:
31
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform