By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

How could I hide class information in Class Library

P: n/a
hi, there
I build a Class Library, I write a class A to implement interface IA. The
problem is when I give the dll file to others, thet can get all information
about not only IA, but also A. They can even see my protected members of
class A. How could I hide these informations about class A, just give them
the interface informations.

thanks.
Nov 15 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Ray,
Make class A something other than public, such as internal.

Internal means that only that assembly will be able to see the class.

internal class A : IA
{
// ...
}

Of course this does not protect your class from reflection.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP11.phx.gbl...
hi, there
I build a Class Library, I write a class A to implement interface IA. The
problem is when I give the dll file to others, thet can get all information about not only IA, but also A. They can even see my protected members of
class A. How could I hide these informations about class A, just give them
the interface informations.

thanks.

Nov 15 '05 #2

P: n/a
Yes, this works. But this will generate another problem. User can not new a
interface. IA a = new IA; will not work. and, IA a = new A will not work
too.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Ray,
Make class A something other than public, such as internal.

Internal means that only that assembly will be able to see the class.

internal class A : IA
{
// ...
}

Of course this does not protect your class from reflection.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP11.phx.gbl...
hi, there
I build a Class Library, I write a class A to implement interface IA. The problem is when I give the dll file to others, thet can get all

information
about not only IA, but also A. They can even see my protected members of
class A. How could I hide these informations about class A, just give them the interface informations.

thanks.


Nov 15 '05 #3

P: n/a
Thanks again. I get it and forget my last post which really show my stupid
and lazy.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Ray,
Make class A something other than public, such as internal.

Internal means that only that assembly will be able to see the class.

internal class A : IA
{
// ...
}

Of course this does not protect your class from reflection.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP11.phx.gbl...
hi, there
I build a Class Library, I write a class A to implement interface IA. The problem is when I give the dll file to others, thet can get all

information
about not only IA, but also A. They can even see my protected members of
class A. How could I hide these informations about class A, just give them the interface informations.

thanks.


Nov 15 '05 #4

P: n/a
Ray,
Yes that would be a problem. Normally in cases like that I create a factory
class with a static factory method to create an instance of the object, the
factory method would have a return type of IA, however it would return an
instance of the A class. Or I use a Plugin type pattern to load an instance
of the class, based on entries in the configuration file.

http://www.martinfowler.com/eaaCatalog/plugin.html

Hope this helps
Jay
"Ray Z" <su*********@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Yes, this works. But this will generate another problem. User can not new a interface. IA a = new IA; will not work. and, IA a = new A will not work
too.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:u3**************@TK2MSFTNGP12.phx.gbl...
Ray,
Make class A something other than public, such as internal.

Internal means that only that assembly will be able to see the class.

internal class A : IA
{
// ...
}

Of course this does not protect your class from reflection.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP11.phx.gbl...
hi, there
I build a Class Library, I write a class A to implement interface IA. The problem is when I give the dll file to others, thet can get all

information
about not only IA, but also A. They can even see my protected members of class A. How could I hide these informations about class A, just give them the interface informations.

thanks.



Nov 15 '05 #5

P: n/a

Hi Ray,

Did you resolve your problem?
I think jay's class factory solution is suitable, it is somewhat similiar
to the COM implementation.

If you still have any question, please feel free to let met know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Ray Z" <su*********@hotmail.com>
| References: <ej**************@TK2MSFTNGP11.phx.gbl>
<u3**************@TK2MSFTNGP12.phx.gbl>
| Subject: Re: How could I hide class information in Class Library
| Date: Mon, 13 Oct 2003 17:29:49 -0400
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#$**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191097
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks again. I get it and forget my last post which really show my stupid
| and lazy.
|
| "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
message
| news:u3**************@TK2MSFTNGP12.phx.gbl...
| > Ray,
| > Make class A something other than public, such as internal.
| >
| > Internal means that only that assembly will be able to see the class.
| >
| > internal class A : IA
| > {
| > // ...
| > }
| >
| > Of course this does not protect your class from reflection.
| >
| > Hope this helps
| > Jay
| >
| > "Ray Z" <su*********@hotmail.com> wrote in message
| > news:ej**************@TK2MSFTNGP11.phx.gbl...
| > > hi, there
| > > I build a Class Library, I write a class A to implement interface IA.
| The
| > > problem is when I give the dll file to others, thet can get all
| > information
| > > about not only IA, but also A. They can even see my protected members
of
| > > class A. How could I hide these informations about class A, just give
| them
| > > the interface informations.
| > >
| > > thanks.
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #6

P: n/a
Thanks. Mmm, I solve part of the problem. I put internal keywork in front of
the members and functions I do not want user to see. like Jay told me. by
this way, user can not see the members easily. but, still, they can get
information when they debug the program which use this dll. Is this called
reflection? can I avoid it by using factory?

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:nL**************@cpmsftngxa06.phx.gbl...

Hi Ray,

Did you resolve your problem?
I think jay's class factory solution is suitable, it is somewhat similiar
to the COM implementation.

If you still have any question, please feel free to let met know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Ray Z" <su*********@hotmail.com>
| References: <ej**************@TK2MSFTNGP11.phx.gbl>
<u3**************@TK2MSFTNGP12.phx.gbl>
| Subject: Re: How could I hide class information in Class Library
| Date: Mon, 13 Oct 2003 17:29:49 -0400
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#$**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191097 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks again. I get it and forget my last post which really show my stupid | and lazy.
|
| "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
message
| news:u3**************@TK2MSFTNGP12.phx.gbl...
| > Ray,
| > Make class A something other than public, such as internal.
| >
| > Internal means that only that assembly will be able to see the class.
| >
| > internal class A : IA
| > {
| > // ...
| > }
| >
| > Of course this does not protect your class from reflection.
| >
| > Hope this helps
| > Jay
| >
| > "Ray Z" <su*********@hotmail.com> wrote in message
| > news:ej**************@TK2MSFTNGP11.phx.gbl...
| > > hi, there
| > > I build a Class Library, I write a class A to implement interface IA. | The
| > > problem is when I give the dll file to others, thet can get all
| > information
| > > about not only IA, but also A. They can even see my protected members of
| > > class A. How could I hide these informations about class A, just give | them
| > > the interface informations.
| > >
| > > thanks.
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #7

P: n/a

Hi Ray,

I think you can not avoid reflection.
You can use ILasm.exe to open you dll, you will see all the member of the
assembly, so the reflection will also can retrieve it.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Ray Z" <su*********@hotmail.com>
| References: <ej**************@TK2MSFTNGP11.phx.gbl>
<u3**************@TK2MSFTNGP12.phx.gbl>
<#$**************@TK2MSFTNGP10.phx.gbl>
<nL**************@cpmsftngxa06.phx.gbl>
| Subject: Re: How could I hide class information in Class Library
| Date: Tue, 14 Oct 2003 10:21:39 -0400
| Lines: 91
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <e4**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191208
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks. Mmm, I solve part of the problem. I put internal keywork in front
of
| the members and functions I do not want user to see. like Jay told me. by
| this way, user can not see the members easily. but, still, they can get
| information when they debug the program which use this dll. Is this called
| reflection? can I avoid it by using factory?
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:nL**************@cpmsftngxa06.phx.gbl...
| >
| > Hi Ray,
| >
| > Did you resolve your problem?
| > I think jay's class factory solution is suitable, it is somewhat
similiar
| > to the COM implementation.
| >
| > If you still have any question, please feel free to let met know.
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Ray Z" <su*********@hotmail.com>
| > | References: <ej**************@TK2MSFTNGP11.phx.gbl>
| > <u3**************@TK2MSFTNGP12.phx.gbl>
| > | Subject: Re: How could I hide class information in Class Library
| > | Date: Mon, 13 Oct 2003 17:29:49 -0400
| > | Lines: 39
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Message-ID: <#$**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:191097
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Thanks again. I get it and forget my last post which really show my
| stupid
| > | and lazy.
| > |
| > | "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
| > message
| > | news:u3**************@TK2MSFTNGP12.phx.gbl...
| > | > Ray,
| > | > Make class A something other than public, such as internal.
| > | >
| > | > Internal means that only that assembly will be able to see the
class.
| > | >
| > | > internal class A : IA
| > | > {
| > | > // ...
| > | > }
| > | >
| > | > Of course this does not protect your class from reflection.
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | > "Ray Z" <su*********@hotmail.com> wrote in message
| > | > news:ej**************@TK2MSFTNGP11.phx.gbl...
| > | > > hi, there
| > | > > I build a Class Library, I write a class A to implement interface
| IA.
| > | The
| > | > > problem is when I give the dll file to others, thet can get all
| > | > information
| > | > > about not only IA, but also A. They can even see my protected
| members
| > of
| > | > > class A. How could I hide these informations about class A, just
| give
| > | them
| > | > > the interface informations.
| > | > >
| > | > > thanks.
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #8

P: n/a
Thanks, Jeffrey. But, I think there should (or must) has a way to hide
implementation when you want to sell component, right?

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:wl**************@cpmsftngxa06.phx.gbl...

Hi Ray,

I think you can not avoid reflection.
You can use ILasm.exe to open you dll, you will see all the member of the
assembly, so the reflection will also can retrieve it.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Ray Z" <su*********@hotmail.com>
| References: <ej**************@TK2MSFTNGP11.phx.gbl>
<u3**************@TK2MSFTNGP12.phx.gbl>
<#$**************@TK2MSFTNGP10.phx.gbl>
<nL**************@cpmsftngxa06.phx.gbl>
| Subject: Re: How could I hide class information in Class Library
| Date: Tue, 14 Oct 2003 10:21:39 -0400
| Lines: 91
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <e4**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191208 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks. Mmm, I solve part of the problem. I put internal keywork in front of
| the members and functions I do not want user to see. like Jay told me. by | this way, user can not see the members easily. but, still, they can get
| information when they debug the program which use this dll. Is this called | reflection? can I avoid it by using factory?
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:nL**************@cpmsftngxa06.phx.gbl...
| >
| > Hi Ray,
| >
| > Did you resolve your problem?
| > I think jay's class factory solution is suitable, it is somewhat
similiar
| > to the COM implementation.
| >
| > If you still have any question, please feel free to let met know.
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Ray Z" <su*********@hotmail.com>
| > | References: <ej**************@TK2MSFTNGP11.phx.gbl>
| > <u3**************@TK2MSFTNGP12.phx.gbl>
| > | Subject: Re: How could I hide class information in Class Library
| > | Date: Mon, 13 Oct 2003 17:29:49 -0400
| > | Lines: 39
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Message-ID: <#$**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: x42071bc2.ip.e-nt.net 66.7.27.194
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:191097
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Thanks again. I get it and forget my last post which really show my
| stupid
| > | and lazy.
| > |
| > | "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
| > message
| > | news:u3**************@TK2MSFTNGP12.phx.gbl...
| > | > Ray,
| > | > Make class A something other than public, such as internal.
| > | >
| > | > Internal means that only that assembly will be able to see the
class.
| > | >
| > | > internal class A : IA
| > | > {
| > | > // ...
| > | > }
| > | >
| > | > Of course this does not protect your class from reflection.
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | > "Ray Z" <su*********@hotmail.com> wrote in message
| > | > news:ej**************@TK2MSFTNGP11.phx.gbl...
| > | > > hi, there
| > | > > I build a Class Library, I write a class A to implement interface | IA.
| > | The
| > | > > problem is when I give the dll file to others, thet can get all
| > | > information
| > | > > about not only IA, but also A. They can even see my protected
| members
| > of
| > | > > class A. How could I hide these informations about class A, just
| give
| > | them
| > | > > the interface informations.
| > | > >
| > | > > thanks.
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #9

P: n/a
Ray,
'internal' allows you to 'logically' hide implementation, in that other
assemblies cannot get to that implementation by simply referring to your
assembly, using your object in the C# source & compiling. Via Reflection
they can get to the object.

What it sounds like you are actually asking about is 'physically' hiding the
implementation, which is called Obfuscation. Obfuscation modifies your
assembly so that its really really hard to get the gest of the
implementation out. Note there are ways both instead of & in addition to
Obfuscation that you can use to protect your assembly.

VS.NET 2003 includes Dotfuscator Community Edition.

I haven't done a lot with Obfuscation, if you search the newsgroups for
Obfuscation you should hit a number of links for more info.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:uR*************@tk2msftngp13.phx.gbl...
Thanks, Jeffrey. But, I think there should (or must) has a way to hide
implementation when you want to sell component, right?

<<snip>>
Nov 15 '05 #10

P: n/a
Yes. obfuscation is what I am looking for. Thanks.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
Ray,
'internal' allows you to 'logically' hide implementation, in that other
assemblies cannot get to that implementation by simply referring to your
assembly, using your object in the C# source & compiling. Via Reflection
they can get to the object.

What it sounds like you are actually asking about is 'physically' hiding the implementation, which is called Obfuscation. Obfuscation modifies your
assembly so that its really really hard to get the gest of the
implementation out. Note there are ways both instead of & in addition to
Obfuscation that you can use to protect your assembly.

VS.NET 2003 includes Dotfuscator Community Edition.

I haven't done a lot with Obfuscation, if you search the newsgroups for
Obfuscation you should hit a number of links for more info.

Hope this helps
Jay

"Ray Z" <su*********@hotmail.com> wrote in message
news:uR*************@tk2msftngp13.phx.gbl...
Thanks, Jeffrey. But, I think there should (or must) has a way to hide
implementation when you want to sell component, right?

<<snip>>

Nov 15 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.