473,769 Members | 7,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding method from everyone but two assemblies.

I have assembly a, b and c. Assembly b has a static method in one of
its classes that i would like classes in a and c to access but no other
assembly.

It would be similar to internal but with the ability to specify which
classes could access this method.

I know this doesn't exist but a declaration like:

[InternalTo(A.dl l, C.dll)]
internal static Method()...

I guess i could check the call stack in Method for callers that are at
the top of the stack are a.dll or c.dll. Is there a better way?

dan
Feb 6 '07 #1
6 1594
In article <Oj************ **@TK2MSFTNGP03 .phx.gbl>,
da*******@bigfo ot.com says...
I have assembly a, b and c. Assembly b has a static method in one of
its classes that i would like classes in a and c to access but no other
assembly.

It would be similar to internal but with the ability to specify which
classes could access this method.
Why? It seems like the easiest way to do what you want is just
duplicate the code as private in the two spots that need it. I hate
duplicating code, but you've got some pretty strict requirements that,
in this case, are easily solved with a copy/paste of the one method.

--
Patrick Steele
http://weblogs.asp.net/psteele
Feb 6 '07 #2
Dan,
>It would be similar to internal but with the ability to specify which
classes could access this method.
There's the InternalsVisibl eToAttribute, but it applies only to
assemblies. There's nothing as granular as what you're asking for.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 6 '07 #3
Hasve you looked at GetEntryAssembl y or GetCallingAssem bly to see if it can
identify if its either of the unwanted assemblys calling your static method.

http://msdn2.microsoft.com/en-us/lib...gassembly.aspx

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Dan Holmes" <da*******@bigf oot.comwrote in message
news:Oj******** ******@TK2MSFTN GP03.phx.gbl...
>I have assembly a, b and c. Assembly b has a static method in one of its
classes that i would like classes in a and c to access but no other
assembly.

It would be similar to internal but with the ability to specify which
classes could access this method.

I know this doesn't exist but a declaration like:

[InternalTo(A.dl l, C.dll)]
internal static Method()...

I guess i could check the call stack in Method for callers that are at the
top of the stack are a.dll or c.dll. Is there a better way?

dan

Feb 6 '07 #4
I use the InternalsVisibl eTo attribute in a few places:

[assembly:
InternalsVisibl eTo("Coversant. SoapBox.Service s.SomeService,P ublicKey=....")]

This has worked very well so far. It's not quite what you're looking for,
but it's close.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise , MVP C#
http://www.coversant.net/blogs/cmullins

"Dan Holmes" <da*******@bigf oot.comwrote in message
news:Oj******** ******@TK2MSFTN GP03.phx.gbl...
>I have assembly a, b and c. Assembly b has a static method in one of its
classes that i would like classes in a and c to access but no other
assembly.

It would be similar to internal but with the ability to specify which
classes could access this method.

I know this doesn't exist but a declaration like:

[InternalTo(A.dl l, C.dll)]
internal static Method()...

I guess i could check the call stack in Method for callers that are at the
top of the stack are a.dll or c.dll. Is there a better way?

dan

Feb 6 '07 #5
Hi,

You can use CAS.

Sign all of your assemblies with the same strong-name, then Demand the
StrongNameIdent ityPermissionAt tribute attribute on your public, static
methods with your assembly signature's public key so they cannot be called
from other assemblies.

The PublicKey value must be a hexadecimal string. You can use the Strong
Name utility (sn.exe) to create the key with which you'll sign your assembly
(although Visual Studio can be used to perform this operation for you).
The -k switch will create the public/private key pair. If you use -k to
create a file named, "key.snk" then use that file as input to the -p switch.
The file output from the -p switch can then be used as input to the -tp
switch to produce the hexadecimal representation of the public key that you
can assign to the PublicKey property of the
StrongNameIdent ityPermissionAt tribute attribute. Make sure you use the full
public key and not just the token.

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in Visual Studio 2005)

"Dan Holmes" <da*******@bigf oot.comwrote in message
news:Oj******** ******@TK2MSFTN GP03.phx.gbl...
>I have assembly a, b and c. Assembly b has a static method in one of its
classes that i would like classes in a and c to access but no other
assembly.

It would be similar to internal but with the ability to specify which
classes could access this method.

I know this doesn't exist but a declaration like:

[InternalTo(A.dl l, C.dll)]
internal static Method()...

I guess i could check the call stack in Method for callers that are at the
top of the stack are a.dll or c.dll. Is there a better way?

dan

Feb 6 '07 #6
Mattias Sjögren wrote:
Dan,
>It would be similar to internal but with the ability to specify which
classes could access this method.

There's the InternalsVisibl eToAttribute, but it applies only to
assemblies. There's nothing as granular as what you're asking for.
Mattias
That will do it. I specified the most restrictive case but really only
needed what this attribute provides.

thanks

dan
Feb 7 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
15371
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain, it calls the static method that I am staticly linked to and not the static method in the dynamicly...
6
538
by: harrylmh | last post by:
Hi, I'm learning C# and I just don't quite understand the need for polymorphism. why do we need to use it? how does a base class variable holding a derived class instance do any good? Also, what's the difference between method hiding and overriding when they're both still overriding the base method. Thanks
4
4155
by: Sharon Tal | last post by:
Hi all. I am trying to figure out the differences between overriding and hiding a method name. The only difference i can see, is that with name hiding i can change the method access level. Are there any other differences? Thanks, Sharon.
17
2918
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that when the Poodle is upcast to the Dog (in its wildest dreams) it then says "bow wow" where the bernard always says "woof" (see code). Basically, it appears that I'm hiding the poodle's speak method from everything except the poodle. Why would I...
7
5177
by: Dennis | last post by:
I have a class named myclass that inheirits from "baseclass". There is a property of "baseclass" that I don't want exposed in the IDE. The MSDN documentation says" "A derived type can hide an inherited member by defining a new member with the same signature. This might be done to make a previously public member private or to define new behavior for an inherited method that is marked as final. " However, this does not hide the...
9
4986
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function hiding saves the day. I know there exists one, I'd just like to hear about it. thanks and have a nice day.
5
2119
by: PIEBALD | last post by:
I was trying to break some polymorphism, expecting it not to work, but I'm a curious sort. I was seeing what happens when a derived class tries to hide an inherited method with a private new method, expecting an error or warning; I got neither with the result that the inherited method does _not_ get hidden (i.e. not possibe to break polymorphism/inheritance this way, yay!) My question then is, why is there no warning that the code may...
9
2727
by: Andrew Robinson | last post by:
I have class A which inherits from class B. B contains the following virtual method: public virtual List<TSelect() { return new List<T>(); } Is there any way to make private or otherwise hide this method within A so that classes instantiating A don't see it?
162
10298
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language, but why does it miss one of the basic principles of OOP? Will it ever be added to python?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.