Internal type from Sealed class extraction

T

Tamir Khason

I do not know if it is possible, but
I have Class Library with some sealed classes
I have methods returns those classes from this library
I want NOT to reference Library with sealed classes, but use only internal
classes, SO
I can not inherit those sealed classes
I can not (or maybe I can for some kind) to build types or interfaces from
those classes to use in my class

Please advice.
Follow the example:

public namespace Foo1
{
public sealed class FooSealedClass
{}
}

public namespace Foo2
{
public class MyClass
{
FooSealedClass sealed = new FooSealedClass();
public static Type FooUnSealed = typeof(Foo1.FooSealedClass);
//Somethig like that
public static FooUnSealed GetFooUnSealedStat {return sealed;}
public FooUnSealed GetFooUnSealed {return sealed;}
}
}

using Foo2;
public namespace MyInvocator
{
public class Inv
{
public Inv()
{
MyClass myclass = new MyClass();
FooUnSealed myunsealed1 = MyClass.GetFooUnSealedStat ;
FooUnSealed myunsealed2 = myclass.GetFooUnSealed ;
}
}
}


TNX
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
I'm not very sure of what you want to do.
I havent compiled your code, but these lines will not compile:

FooSealedClass sealed = new FooSealedClass();
public static FooUnSealed GetFooUnSealedStat {return sealed;}

you are trying to use a instance field from a class field.

the sealed only indicate that you cannot inherit from it, nothing more, if
you want for some reason that the classes outside your lib cannot create an
instance of these classes you can do so by declaring the constructor
internal.

If the above is not the intended use, please post more details about it.


cheers,
 
T

Tamir Khason

Sure it will not.
I'm asking how to implement it.,
I want to return from method and use outside sealed class the type of this
sealed class, without referencing it with my invocator and just do not know
how (if at all) possible to implement it.
The architecture I want is seemed like Static library in C++ where all
classes are inside the referenced class.
 
K

Kevin Yu [MSFT]

Hi Tamir

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to return a sealed class to
outside the library. If there is any misunderstanding, please feel free to
let me know.

Just as Ignacio mentioned in his post, sealed keyword only means that this
class cannot be inherited from. We can use this type outside the assembly
if it is public. No other limitation on this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
T

Tamir Khason

The class is in assembly 1, I' using it in assembly 2 by referencing to
assembly 1. I want to use class that one of it's methods is class in
assembly 1 from assembly 3 without referencing to assembly 1, just to
assembyl 2
I think it clearer now
 
K

Kevin Yu [MSFT]

Hi Tamir,

I think you need to call a method in assembly 1 from assembly 3 through
asembly 2. Please correct me if any misunderstanding is here.

I think this depends on how the method is declared in assembly 1. Because
if the class in assemly 1 is declared as internal, none of other assemblies
can see it. However, if it is declared as public, we can surely call it
from assembly 3.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top