Hello Paul,
Nice one

... Hadn't thought of that...
Jesse
> Does this work for you???
>
> using System;
>
> using System.Collections.Generic;
>
> using System.Linq;
>
> using System.Text;
>
> namespace Generics_test
>
> {
>
> class Program
>
> {
>
> static void Main(string[] args)
>
> {
>
> Console.WriteLine(A.GetType().Name);
>
> Console.WriteLine(B.GetType().Name);
>
> Console.ReadLine();
>
> }
>
> public abstract class BaseClass<T> where T : BaseClass<T>
>
> {
>
> public new static Type GetType()
>
> {
>
> return typeof(T);
>
> }
>
> }
>
> public class A : BaseClass<A>
>
> {
>
> }
>
> public class B : BaseClass<B>
>
> {
>
> }
>
> }
>
> }
>
> "Jesse Houwing" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Hello Ivan,
>>
>>> Jesse,
>>>
>>> Example of course is simplified. I have many different objects
>>> inheriting from BaseClass and they all need same functionality but
>>> it depends on specific class name. To be more specific, it's user
>>> based permissions. So, some users have access to MyClassX and don't
>>> have access to MyClassY. Code to check is all the same except that I
>>> need to pass Typename to DB function. Don't ask, I can't change
>>> architecture. All I want is to avoid programming "GetType" or actual
>>> code in every child object.
>>>
>> So you need access to the type, before you have created an instance?
>> Do I understand you correctly?
>>
>> The only way to do that is to use:
>> typeof(MyClassY).Name
>> Or you could use Type.GetType(string name) to get access to the Type
>> object, but then you'd already have it's name as a string...
>>
>> The alternative is to implement a static function in every class
>> returning the name (probably using the above syntax).
>>
>> If you have access to an instance, before checking security, you can
>> call:
>>
>> this.GetType().Name
>>
>> and you could put that in a public or protected method of your base
>> class, so that you have easier access like so:
>>
>> public string GetTypeName()
>> {
>> return this.GetType().Name;
>> }
>> I'd use a method, as it fits nicely besides the already existing
>> GetType() method inherited from Object.
>>
>> No need for any override or abstract methods.
>>
>> Jesse
>>
>>> "Jesse Houwing" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>
>>>> Hello Ivan,
>>>>
>>>>> Here is what I try to accomplish.
>>>>> I have class that implements base class. "GetyType" static
>>>>> property
>>>>> is
>>>>> in
>>>>> BaseClass object but will be accessed through implementing
>>>>> objects.
>>>>> How do I
>>>>> know type of actual object?
>>>>> So, I want to return "MyClassX" if I do MyClassX.GetType
>>>>> public abstract class BaseClass
>>>>> {
>>>>> public static string GetType
>>>>>
>>>>> {get{return typeof(??????); }}
>>>>>
>>>>> }
>>>>>
>>>>> public class MyClassX: BaseClass
>>>>>
>>>>> {}
>>>>>
>>>>> Thanks for any help!
>>>>>
>>>> Static methods will not be inherited, so this won't work.
>>>>
>>>> And why are you creating this method anyway, if you have an
>>>> instance, you can call myInstance.GetType(); and if you need to get
>>>> the type statically in code you can use typeof(MyType). And then
>>>> query the Name property of the resulting Type object. you could
>>>> just use this.GetType().Name in every base class to get their
>>>> actual type name.
>>>>
>>>> If you want to do it (even though I see no good reason and
>>>> absolutely do not reccommend it), then you'll have to implement a
>>>> static GetType method or property on each and every class.
>>>>
>>>> --
>>>> Jesse Houwing
>>>> jesse.houwing at sogeti.nl
>> --
>> Jesse Houwing
>> jesse.houwing at sogeti.nl
--
Jesse Houwing
jesse.houwing at sogeti.nl