External callability of member

Greetings,

Given ITypeMemberDeclaration, what is correct way to check if member can
be called from outside of assembly?

It should check for direct calls, like public members of public types and
indirect calls, like override, public interface implementation and so on.
I'm asking just to be sure that I didn't miss some cases. I also think there
may be ready-to-use code in Resharper's API.

Sincerely,
Ilya Ryzhenkov


12 comments

1) Convert it to declared element:

ITypeMember member = (ITypeMember) typeMemberDeclaration.DeclaredElement;

2) Check it accessibility domain

if (member.AccessibilityDomain == AccessibilityDomain.PUBLIC)
{
.....
}

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b1063e48c7edcc58b077a0@news.jetbrains.com...

Greetings,

>

Given ITypeMemberDeclaration, what is correct way to check if member can
be called from outside of assembly?

>

It should check for direct calls, like public members of public types and
indirect calls, like override, public interface implementation and so on.
I'm asking just to be sure that I didn't miss some cases. I also think
there may be ready-to-use code in Resharper's API.

>

Sincerely,
Ilya Ryzhenkov

>



0

It seems there's no ready-to-use code for this task in ReSharper. But besides
public accessibility, you should also check

1) protected accessibilty (can be done like checking for public)
2) explicit implementation of a public interface (check IOverridableMember.QualifiedInterfaceName
for that)
3) internal accessibility in combination with InternalsVisibleTo (not suppported
currently)
4) ...

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

1) Convert it to declared element:

ITypeMember member = (ITypeMember)
typeMemberDeclaration.DeclaredElement;

2) Check it accessibility domain

if (member.AccessibilityDomain == AccessibilityDomain.PUBLIC)
{
.....
}



0

Hello Eugene,

What does AccessibilityDomain means exactly?

It seems that you and Dmitry thinks different here...

EP> 1) Convert it to declared element:
EP>
EP> ITypeMember member = (ITypeMember)
EP> typeMemberDeclaration.DeclaredElement;
EP>
EP> 2) Check it accessibility domain
EP>
EP> if (member.AccessibilityDomain == AccessibilityDomain.PUBLIC)
EP> {
EP> .....
EP> }
Sincerely,
Ilya Ryzhenkov


0

Accessibility domain is the overall accessibility of the type member from
the assembly point of view.

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b1072298c7ee547b08d3ff@news.jetbrains.com...

Hello Eugene,

>

What does AccessibilityDomain means exactly?

>

It seems that you and Dmitry thinks different here...

>

EP> 1) Convert it to declared element:
EP> EP> ITypeMember member = (ITypeMember)
EP> typeMemberDeclaration.DeclaredElement;
EP> EP> 2) Check it accessibility domain
EP> EP> if (member.AccessibilityDomain == AccessibilityDomain.PUBLIC)
EP> {
EP> .....
EP> }
Sincerely,
Ilya Ryzhenkov

>



0

Hello Eugene,

Could you please explain it further? Does it include friend-assembly checks?
Protected members overrides? Quasy-implementation checks?

EP> Accessibility domain is the overall accessibility of the type member
EP> from the assembly point of view.
EP>
Sincerely,
Ilya Ryzhenkov


0

1) Internal visible attribute is not currently supported

2) The accessibility domain of the element means the direct accessibility of
it, i.e. while you can directly reference it. It doesn't count if this
element could be accessed by other means, for example by interface, or by
reflection :)

In other words, the accessibility domain is the intersection of the access
rights the element and all containing elements

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b10724a8c7ee6569f462f8@news.jetbrains.com...

Hello Eugene,

>

Could you please explain it further? Does it include friend-assembly
checks? Protected members overrides? Quasy-implementation checks?

>

EP> Accessibility domain is the overall accessibility of the type member
EP> from the assembly point of view.
EP> Sincerely,
Ilya Ryzhenkov

>



0

Hello Eugene,

I see.

public class A
{
protected class B
{
internal void foo(){} // what's AD of this member?
}
}

EP> 1) Internal visible attribute is not currently supported
EP>
EP> 2) The accessibility domain of the element means the direct
EP> accessibility of it, i.e. while you can directly reference it. It
EP> doesn't count if this element could be accessed by other means, for
EP> example by interface, or by reflection :)
EP>
EP> In other words, the accessibility domain is the intersection of the
EP> access rights the element and all containing elements
EP>
Sincerely,
Ilya Ryzhenkov


0

PROTECTED_AND_INTERNAL


--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b1072528c7ee695f0d6fb8@news.jetbrains.com...

Hello Eugene,

>

I see.

>

public class A
{
protected class B
{
internal void foo(){} // what's AD of this member?
}
}

>

EP> 1) Internal visible attribute is not currently supported
EP> EP> 2) The accessibility domain of the element means the direct
EP> accessibility of it, i.e. while you can directly reference it. It
EP> doesn't count if this element could be accessed by other means, for
EP> example by interface, or by reflection :)
EP> EP> In other words, the accessibility domain is the intersection of
the
EP> access rights the element and all containing elements
EP> Sincerely,
Ilya Ryzhenkov

>



0

In 216, the Accessibility domain entity is refactored according to C# specs

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b1063e48c7edcc58b077a0@news.jetbrains.com...

Greetings,

>

Given ITypeMemberDeclaration, what is correct way to check if member can
be called from outside of assembly?

>

It should check for direct calls, like public members of public types and
indirect calls, like override, public interface implementation and so on.
I'm asking just to be sure that I didn't miss some cases. I also think
there may be ready-to-use code in Resharper's API.

>

Sincerely,
Ilya Ryzhenkov

>



0

Hello Eugene,

Hmm, what does it mean exactly? I did never memorized C# specs. :)

EP> In 216, the Accessibility domain entity is refactored according to
EP> C# specs
EP>
Sincerely,
Ilya Ryzhenkov


0

I mean that along with the access rights, the type member is included (for
example, if access domain is private, then the class will be included in
which this element is accessible).

Such changes are necessary to make precise inconsistent accessibility checks

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:5992f43b10f8c48c7f182fe386ee7@news.jetbrains.com...

Hello Eugene,

>

Hmm, what does it mean exactly? I did never memorized C# specs. :)

>

EP> In 216, the Accessibility domain entity is refactored according to
EP> C# specs
EP> Sincerely,
Ilya Ryzhenkov

>



0

Ilya, maybe it would be easier for us to help you if we know what exactly
you need. For what purpose do you need to check this?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Greetings,

Given ITypeMemberDeclaration, what is correct way to check if member
can be called from outside of assembly?

It should check for direct calls, like public members of public types
and indirect calls, like override, public interface implementation and
so on. I'm asking just to be sure that I didn't miss some cases. I
also think there may be ready-to-use code in Resharper's API.

Sincerely,
Ilya Ryzhenkov



0

Please sign in to leave a comment.