Make MyClass Implement IMyIfc<MyClass>

Ok my question is that:

I have a class in which i added a method to it.

now i want my class to implement an interface containing that method
and the interface has a parameter 'T' in which i want it to be MyClass, for
example:

Before:
public class MyClass
{
MyClass Clone()
{
implement ...
}
}

What I can do now (not good)
public class MyClass : IClonable
{
MyClass Clone()
{
implement ...
}
}

What I want to do
public class MyClass : IClonable<![CDATA[]]>
{
MyClass Clone()
{
implement ...
}
}

please help.

btw thanks for the former help, it helped alot thanks!!!



7 comments
Comment actions Permalink

As I've understood you, you need to build generic type and add it to class'
extends list? Or something else?

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:f9vnrk$49c$1@is.intellij.net...

Ok my question is that:

>

I have a class in which i added a method to it.

>

now i want my class to implement an interface containing that method
and the interface has a parameter 'T' in which i want it to be MyClass,
for example:

>

Before:
public class MyClass
{
MyClass Clone()
{
implement ...
}
}

>

What I can do now (not good)
public class MyClass : IClonable
{
MyClass Clone()
{
implement ...
}
}

>

What I want to do
public class MyClass : IClonable<MyClass>
{
MyClass Clone()
{
implement ...
}
}

>

please help.

>

btw thanks for the former help, it helped alot thanks!!!

>
>



0
Comment actions Permalink

I want to know how i can implement an interface and specifiy the parameter
which i'm implementing

for example , i want the class "MyClass" to implement IComparable with
altering the T parameter
with MyClass, i.e.

  • HERE *

public class MyClass: IComparable<![CDATA[ { //... } Thanks, Guy. "Eugene Pasynkov (JetBrains)" ]]> wrote in
message news:fa10t4$e5d$1@is.intellij.net...

As I've understood you, you need to build generic type and add it to
class' extends list? Or something else?

>

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:f9vnrk$49c$1@is.intellij.net...

>> Ok my question is that:
>>
>> I have a class in which i added a method to it.
>>
>> now i want my class to implement an interface containing that method
>> and the interface has a parameter 'T' in which i want it to be MyClass,
>> for example:
>>
>> Before:
>> public class MyClass
>> {
>> MyClass Clone()
>> {
>> implement ...
>> }
>> }
>>
>> What I can do now (not good)
>> public class MyClass : IClonable
>> {
>> MyClass Clone()
>> {
>> implement ...
>> }
>> }
>>
>> What I want to do
>> public class MyClass : IClonable<![CDATA[ >> { >> MyClass Clone() >> { >> implement ... >> } >> } >> >> please help. >> >> btw thanks for the former help, it helped alot thanks!!! >> >> >> >]]>



0
Comment actions Permalink

I see.

The key object is "IDeclaredType" - its a type instance with given type
arguments.
You have to create it, for example:

ITypeElement icomparable =
PredefinedType.GetInstance(solution).GenericIComparable.GetTypeElement();
IDeclaredType typeInstance = TypeFactory.CreateType (icomparable, new
IType[] (TypeFactory.CreateType(myClassTypeElement)));


the you can add that "typeInstance" to the class extends list


--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:fa2317$gr8$1@is.intellij.net...
>I want to know how i can implement an interface and specifiy the parameter
>which i'm implementing
>

for example , i want the class "MyClass" to implement IComparable with
altering the T parameter
with MyClass, i.e.

>

  • * HERE *

public class MyClass: IComparable<MyClass>
{
//...
}

>
>

Thanks,
Guy.

>
>

"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:fa10t4$e5d$1@is.intellij.net...

>> As I've understood you, you need to build generic type and add it to
>> class' extends list? Or something else?
>>
>> --
>> Eugene Pasynkov
>> Developer
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> "Ga" <![CDATA[ wrote in message >> news:f9vnrk$49c$1@is.intellij.net... >>> Ok my question is that: >>> >>> I have a class in which i added a method to it. >>> >>> now i want my class to implement an interface containing that method >>> and the interface has a parameter 'T' in which i want it to be MyClass, >>> for example: >>> >>> Before: >>> public class MyClass >>> { >>> MyClass Clone() >>> { >>> implement ... >>> } >>> } >>> >>> What I can do now (not good) >>> public class MyClass : IClonable >>> { >>> MyClass Clone() >>> { >>> implement ... >>> } >>> } >>> >>> What I want to do >>> public class MyClass : IClonable >>> { >>> MyClass Clone() >>> { >>> implement ... >>> } >>> } >>> >>> please help. >>> >>> btw thanks for the former help, it helped alot thanks!!! >>> >>> >>> >> >> >]]>



0
Comment actions Permalink

Here is the code i wrote to generate what you've said:

ITypeElement icomparable =
projectDeclarationsCache.GetTypeElementByCLRName("System.IComparable`1");
IDeclaredType typeInstance =
TypeFactory.CreateType(icomparable,new
IType[]{TypeFactory.CreateType(TokenAccessor.ClassDeclaration.DeclaredElement)});

Unfortunately, I don't seem to find a way to add it to the class.
The only logical method is AddSuperInterface but i don't seem to find a way
to do so without
dropping the type parameter.

please help me,
Thanks,
guy.


"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:fa46ii$3fi$1@is.intellij.net...
>I see.
>

The key object is "IDeclaredType" - its a type instance with given type
arguments.
You have to create it, for example:

>

ITypeElement icomparable =
PredefinedType.GetInstance(solution).GenericIComparable.GetTypeElement();
IDeclaredType typeInstance = TypeFactory.CreateType (icomparable, new
IType[] (TypeFactory.CreateType(myClassTypeElement)));

>
>

the you can add that "typeInstance" to the class extends list

>
>

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:fa2317$gr8$1@is.intellij.net...

>>I want to know how i can implement an interface and specifiy the parameter
>>which i'm implementing
>>
>> for example , i want the class "MyClass" to implement IComparable with
>> altering the T parameter
>> with MyClass, i.e.
>>
>> * HERE *
>> public class MyClass: IComparable<![CDATA[ >> { >> //... >> } >> >> >> Thanks, >> Guy. >> >> >> "Eugene Pasynkov (JetBrains)" wrote in >> message news:fa10t4$e5d$1@is.intellij.net... >>> As I've understood you, you need to build generic type and add it to >>> class' extends list? Or something else? >>> >>> -- >>> Eugene Pasynkov >>> Developer >>> JetBrains, Inc >>> http://www.jetbrains.com >>> "Develop with pleasure!" >>> "Ga" wrote in message >>> news:f9vnrk$49c$1@is.intellij.net... >>>> Ok my question is that: >>>> >>>> I have a class in which i added a method to it. >>>> >>>> now i want my class to implement an interface containing that method >>>> and the interface has a parameter 'T' in which i want it to be MyClass, >>>> for example: >>>> >>>> Before: >>>> public class MyClass >>>> { >>>> MyClass Clone() >>>> { >>>> implement ... >>>> } >>>> } >>>> >>>> What I can do now (not good) >>>> public class MyClass : IClonable >>>> { >>>> MyClass Clone() >>>> { >>>> implement ... >>>> } >>>> } >>>> >>>> What I want to do >>>> public class MyClass : IClonable >>>> { >>>> MyClass Clone() >>>> { >>>> implement ... >>>> } >>>> } >>>> >>>> please help. >>>> >>>> btw thanks for the former help, it helped alot thanks!!! >>>> >>>> >>>> >>> >>> >> >> >]]>



0
Comment actions Permalink

What do you mean "without type parameter"????
It CAN'T be without it!

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:fakvsd$nsg$1@is.intellij.net...

Here is the code i wrote to generate what you've said:

>

ITypeElement icomparable =
projectDeclarationsCache.GetTypeElementByCLRName("System.IComparable`1");
IDeclaredType typeInstance =
TypeFactory.CreateType(icomparable,new
IType[]{TypeFactory.CreateType(TokenAccessor.ClassDeclaration.DeclaredElement)});

>

Unfortunately, I don't seem to find a way to add it to the class.
The only logical method is AddSuperInterface but i don't seem to find a
way to do so without
dropping the type parameter.

>

please help me,
Thanks,
guy.

>
>

"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:fa46ii$3fi$1@is.intellij.net...

>>I see.
>>
>> The key object is "IDeclaredType" - its a type instance with given type
>> arguments.
>> You have to create it, for example:
>>
>> ITypeElement icomparable =
>> PredefinedType.GetInstance(solution).GenericIComparable.GetTypeElement();
>> IDeclaredType typeInstance = TypeFactory.CreateType (icomparable, new
>> IType[] (TypeFactory.CreateType(myClassTypeElement)));
>>
>>
>> the you can add that "typeInstance" to the class extends list
>>
>>
>> --
>> Eugene Pasynkov
>> Developer
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> "Ga" <![CDATA[ wrote in message >> news:fa2317$gr8$1@is.intellij.net... >>>I want to know how i can implement an interface and specifiy the >>>parameter which i'm implementing >>> >>> for example , i want the class "MyClass" to implement IComparable with >>> altering the T parameter >>> with MyClass, i.e. >>> >>> * HERE * >>> public class MyClass: IComparable >>> { >>> //... >>> } >>> >>> >>> Thanks, >>> Guy. >>> >>> >>> "Eugene Pasynkov (JetBrains)" wrote in >>> message news:fa10t4$e5d$1@is.intellij.net... >>>> As I've understood you, you need to build generic type and add it to >>>> class' extends list? Or something else? >>>> >>>> -- >>>> Eugene Pasynkov >>>> Developer >>>> JetBrains, Inc >>>> http://www.jetbrains.com >>>> "Develop with pleasure!" >>>> "Ga" wrote in message >>>> news:f9vnrk$49c$1@is.intellij.net... >>>>> Ok my question is that: >>>>> >>>>> I have a class in which i added a method to it. >>>>> >>>>> now i want my class to implement an interface containing that method >>>>> and the interface has a parameter 'T' in which i want it to be >>>>> MyClass, for example: >>>>> >>>>> Before: >>>>> public class MyClass >>>>> { >>>>> MyClass Clone() >>>>> { >>>>> implement ... >>>>> } >>>>> } >>>>> >>>>> What I can do now (not good) >>>>> public class MyClass : IClonable >>>>> { >>>>> MyClass Clone() >>>>> { >>>>> implement ... >>>>> } >>>>> } >>>>> >>>>> What I want to do >>>>> public class MyClass : IClonable >>>>> { >>>>> MyClass Clone() >>>>> { >>>>> implement ... >>>>> } >>>>> } >>>>> >>>>> please help. >>>>> >>>>> btw thanks for the former help, it helped alot thanks!!! >>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> >]]>



0
Comment actions Permalink

I meat that the only way i could added the generic interface
to the class declaration is without the generic parameters specification,

for example, i only succeeded adding the interface to the class like the
following:
public class MyClass : IComparable<![CDATA[<> {...} and not adding it: public class MyClass : IComparable {...} could you please refer me to the method that given the "IDeclaredType typeInstance" member, i could add it to the class, with the generic parameter specification... thank you very much! Guy. "Eugene Pasynkov (JetBrains)" ]]> wrote in
message news:fam3fo$fhd$1@is.intellij.net...

What do you mean "without type parameter"????
It CAN'T be without it!

>

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ga" <t4m.productions@gmail.com> wrote in message
news:fakvsd$nsg$1@is.intellij.net...

>> Here is the code i wrote to generate what you've said:
>>
>> ITypeElement icomparable =
>> projectDeclarationsCache.GetTypeElementByCLRName("System.IComparable`1");
>> IDeclaredType typeInstance =
>> TypeFactory.CreateType(icomparable,new
>> IType[]{TypeFactory.CreateType(TokenAccessor.ClassDeclaration.DeclaredElement)});
>>
>> Unfortunately, I don't seem to find a way to add it to the class.
>> The only logical method is AddSuperInterface but i don't seem to find a
>> way to do so without
>> dropping the type parameter.
>>
>> please help me,
>> Thanks,
>> guy.
>>
>>
>> "Eugene Pasynkov (JetBrains)" <![CDATA[ wrote in >> message news:fa46ii$3fi$1@is.intellij.net... >>>I see. >>> >>> The key object is "IDeclaredType" - its a type instance with given type >>> arguments. >>> You have to create it, for example: >>> >>> ITypeElement icomparable = >>> PredefinedType.GetInstance(solution).GenericIComparable.GetTypeElement(); >>> IDeclaredType typeInstance = TypeFactory.CreateType (icomparable, new >>> IType[] (TypeFactory.CreateType(myClassTypeElement))); >>> >>> >>> the you can add that "typeInstance" to the class extends list >>> >>> >>> -- >>> Eugene Pasynkov >>> Developer >>> JetBrains, Inc >>> http://www.jetbrains.com >>> "Develop with pleasure!" >>> "Ga" wrote in message >>> news:fa2317$gr8$1@is.intellij.net... >>>>I want to know how i can implement an interface and specifiy the >>>>parameter which i'm implementing >>>> >>>> for example , i want the class "MyClass" to implement IComparable with >>>> altering the T parameter >>>> with MyClass, i.e. >>>> >>>> * HERE * >>>> public class MyClass: IComparable >>>> { >>>> //... >>>> } >>>> >>>> >>>> Thanks, >>>> Guy. >>>> >>>> >>>> "Eugene Pasynkov (JetBrains)" wrote in >>>> message news:fa10t4$e5d$1@is.intellij.net... >>>>> As I've understood you, you need to build generic type and add it to >>>>> class' extends list? Or something else? >>>>> >>>>> -- >>>>> Eugene Pasynkov >>>>> Developer >>>>> JetBrains, Inc >>>>> http://www.jetbrains.com >>>>> "Develop with pleasure!" >>>>> "Ga" wrote in message >>>>> news:f9vnrk$49c$1@is.intellij.net... >>>>>> Ok my question is that: >>>>>> >>>>>> I have a class in which i added a method to it. >>>>>> >>>>>> now i want my class to implement an interface containing that method >>>>>> and the interface has a parameter 'T' in which i want it to be >>>>>> MyClass, for example: >>>>>> >>>>>> Before: >>>>>> public class MyClass >>>>>> { >>>>>> MyClass Clone() >>>>>> { >>>>>> implement ... >>>>>> } >>>>>> } >>>>>> >>>>>> What I can do now (not good) >>>>>> public class MyClass : IClonable >>>>>> { >>>>>> MyClass Clone() >>>>>> { >>>>>> implement ... >>>>>> } >>>>>> } >>>>>> >>>>>> What I want to do >>>>>> public class MyClass : IClonable >>>>>> { >>>>>> MyClass Clone() >>>>>> { >>>>>> implement ... >>>>>> } >>>>>> } >>>>>> >>>>>> please help. >>>>>> >>>>>> btw thanks for the former help, it helped alot thanks!!! >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> >]]>



0
Comment actions Permalink

Hello Guy,

Unfortunately, the method AddSuperInterface that receives IDeclaredType appeared
only in 4.0. In 3.* you will have to do it via IExtendsListNode. You will
have to write something like

if (classDeclaration.ToTreeNode().ExtendsList == null)
classDeclaration.ToTreeNode().SetExtendsList(...);
else
classDeclaration.ToTreeNode().ExtendsList.AddExtendedInterfaceBefore(...);

I meat that the only way i could added the generic interface to the
class declaration is without the generic parameters specification,

for example, i only succeeded adding the interface to the class like
the
following:
public class MyClass : IComparable<> {...}
and not adding it:
public class MyClass : IComparable<MyClass> {...}
could you please refer me to the method that given the "IDeclaredType
typeInstance" member, i could add it to the class, with the generic
parameter specification...

thank you very much!
Guy.
"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:fam3fo$fhd$1@is.intellij.net...

>> What do you mean "without type parameter"????
>> It CAN'T be without it!
>> --
>> Eugene Pasynkov
>> Developer
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> "Ga" <![CDATA[ wrote in message >> news:fakvsd$nsg$1@is.intellij.net... >>> Here is the code i wrote to generate what you've said: >>> >>> ITypeElement icomparable = >>> projectDeclarationsCache.GetTypeElementByCLRName("System.IComparable >>> `1"); >>> IDeclaredType typeInstance = >>> TypeFactory.CreateType(icomparable,new >>> IType[]{TypeFactory.CreateType(TokenAccessor.ClassDeclaration.Declar >>> edElement)}); >>> Unfortunately, I don't seem to find a way to add it to the class. >>> The only logical method is AddSuperInterface but i don't seem to >>> find a >>> way to do so without >>> dropping the type parameter. >>> please help me, >>> Thanks, >>> guy. >>> "Eugene Pasynkov (JetBrains)" wrote >>> in message news:fa46ii$3fi$1@is.intellij.net... >>> >>>> I see. >>>> >>>> The key object is "IDeclaredType" - its a type instance with given >>>> type >>>> arguments. >>>> You have to create it, for example: >>>> ITypeElement icomparable = >>>> PredefinedType.GetInstance(solution).GenericIComparable.GetTypeElem >>>> ent(); IDeclaredType typeInstance = TypeFactory.CreateType >>>> (icomparable, new IType[] >>>> (TypeFactory.CreateType(myClassTypeElement))); >>>> >>>> the you can add that "typeInstance" to the class extends list >>>> >>>> -- >>>> Eugene Pasynkov >>>> Developer >>>> JetBrains, Inc >>>> http://www.jetbrains.com >>>> "Develop with pleasure!" >>>> "Ga" wrote in message >>>> news:fa2317$gr8$1@is.intellij.net... >>>>> I want to know how i can implement an interface and specifiy the >>>>> parameter which i'm implementing >>>>> >>>>> for example , i want the class "MyClass" to implement IComparable >>>>> with >>>>> altering the T parameter >>>>> with MyClass, i.e. >>>>> * HERE * >>>>> public class MyClass: IComparable >>>>> { >>>>> //... >>>>> } >>>>> Thanks, >>>>> Guy. >>>>> "Eugene Pasynkov (JetBrains)" >>>>> wrote in message news:fa10t4$e5d$1@is.intellij.net... >>>>> >>>>>> As I've understood you, you need to build generic type and add it >>>>>> to class' extends list? Or something else? >>>>>> >>>>>> -- >>>>>> Eugene Pasynkov >>>>>> Developer >>>>>> JetBrains, Inc >>>>>> http://www.jetbrains.com >>>>>> "Develop with pleasure!" >>>>>> "Ga" wrote in message >>>>>> news:f9vnrk$49c$1@is.intellij.net... >>>>>>> Ok my question is that: >>>>>>> >>>>>>> I have a class in which i added a method to it. >>>>>>> >>>>>>> now i want my class to implement an interface containing that >>>>>>> method and the interface has a parameter 'T' in which i want it >>>>>>> to be MyClass, for example: >>>>>>> >>>>>>> Before: >>>>>>> public class MyClass >>>>>>> { >>>>>>> MyClass Clone() >>>>>>> { >>>>>>> implement ... >>>>>>> } >>>>>>> } >>>>>>> What I can do now (not good) >>>>>>> public class MyClass : IClonable >>>>>>> { >>>>>>> MyClass Clone() >>>>>>> { >>>>>>> implement ... >>>>>>> } >>>>>>> } >>>>>>> What I want to do >>>>>>> public class MyClass : IClonable >>>>>>> { >>>>>>> MyClass Clone() >>>>>>> { >>>>>>> implement ... >>>>>>> } >>>>>>> } >>>>>>> please help. >>>>>>> >>>>>>> btw thanks for the former help, it helped alot thanks!!! >>>>>>>]]>
Best regards,
Andrey Simanovsky


0

Please sign in to leave a comment.