本文整理汇总了C#中MethodDefinition.IsVisible方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.IsVisible方法的具体用法?C# MethodDefinition.IsVisible怎么用?C# MethodDefinition.IsVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodDefinition
的用法示例。
在下文中一共展示了MethodDefinition.IsVisible方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMethod
static void ProcessMethod (MethodDefinition method)
{
// only visible API is important for compatibility
if (!method.IsVisible ())
return;
// note: IsSecurityCritical rock is not what we want to use here, since
// we're only interested in the presence (or absence) of the attribute
if (method.HasAttribute (SecurityCritical))
methods.Add (method.ToString ());
}
示例2: ProcessMethod
static void ProcessMethod (MethodDefinition method)
{
// we consider all SafeNativeMethods.* as [SecuritySafeCritical]
// if not then move them into NativeMethods or UnsafeNativeMethods
if (method.IsPInvokeImpl && (method.DeclaringType.Name == "SafeNativeMethods")) {
MarkAsSafeCritical (method);
return;
}
if (!method.HasBody)
return;
// SC code can call SC code
// note: here we use the 'rock' because the [SecurityCritical] attribute
// could be located on the type (or nested type)
if (method.IsSecurityCritical ())
return;
// an icall that is part of the visible API is considered as safe critical
if (method.IsInternalCall && (method.IsVisible () || method.IsVirtual)) {
MarkAsSafeCritical (method);
return;
}
foreach (Instruction ins in method.Body.Instructions) {
MethodReference mr = (ins.Operand as MethodReference);
if (mr == null)
continue;
MethodDefinition md = mr.Resolve ();
if (md == null) {
// this can occurs for some generated types, like Int[,] where the compiler generates a few methods
continue;
}
// again we use the rock here as we want the final result (not the local attribute)
if (md.IsSecurityCritical ()) {
MarkAsSafeCritical (method);
return;
}
}
}
示例3: ProcessMethod
static void ProcessMethod (MethodDefinition method)
{
string comment = null;
// p/invoke methods needs to be [SecurityCritical] to be executed,
// unless they are inside a type named "SafeNativeMethods"
bool sc = (method.IsPInvokeImpl && (method.DeclaringType.Name != "SafeNativeMethods"));
if (sc) {
comment = "p/invoke declaration";
}
if (!sc) {
comment = CheckVerifiability (method);
sc = !String.IsNullOrEmpty (comment);
}
// skip signature check for visible API (we get them from find-sc)
if (!sc && method.HasParameters && !method.IsVisible ()) {
// compilers will add public stuff like: System.Action`1::.ctor(System.Object,System.IntPtr)
if (!method.IsConstructor || (method.DeclaringType as TypeDefinition).BaseType.FullName != "System.MulticastDelegate") {
foreach (ParameterDefinition p in method.Parameters) {
if (!CheckType (p.ParameterType)) {
sc = true;
comment = String.Format ("using '{0}' as a parameter type", p.ParameterType.FullName);
break;
}
}
}
}
// skip signature check for visible API (we get them from find-sc)
if (!sc && !method.IsVisible ()) {
TypeReference rtype = method.ReturnType;
if (!CheckType (rtype)) {
sc = true;
comment = String.Format ("using '{0}' as return type", rtype.FullName);
}
}
// check if this method implements an interface where the corresponding member
// is [SecurityCritical]
TypeDefinition type = method.DeclaringType;
if (!sc && type.HasInterfaces) {
foreach (TypeReference intf in type.Interfaces) {
TypeDefinition td = intf.Resolve ();
if (td == null || !td.HasMethods)
continue;
foreach (MethodDefinition im in td.GetMethods ()) {
if (im.IsSecurityCritical ()) {
if (Compare (method, im)) {
sc = true;
comment = String.Format ("implements '{0}'.", im);
}
}
}
}
}
// if we're overriding a [SecurityCritical] method then we must be one too! or
// if we are [SecurityCritical] then the base method needs to be too!
if (method.IsVirtual && !method.IsAbstract) {
TypeReference tr = method.DeclaringType.BaseType;
if (tr != null) {
TypeDefinition td = tr.Resolve ();
if (td != null) {
foreach (MethodDefinition bm in td.GetMethods ()) {
if (Compare (method, bm)) {
if (!sc) {
if (bm.IsSecurityCritical ()) {
sc = true;
comment = String.Format ("overrides '{0}'.", bm);
}
} else {
if (!bm.IsSecurityCritical ()) {
string bms = bm.ToString ();
if (!methods.ContainsKey (bms)) {
comment = String.Format ("Promoting {0}base method to [SecurityCritical] because of '{1}'.",
bm.IsVisible () ? "[VISIBLE] " : String.Empty, method);
methods.Add (bms, comment);
}
}
}
}
}
}
}
} else {
// note: we don't want to break the override rules above (resulting in TypeLoadException)
// an icall that is NOT part of the visible API is considered as critical (like a p/invoke)
if (method.IsInternalCall && !method.IsVisible ()) {
sc = true;
comment = "internal call";
}
}
if (sc) {
// note: add a warning on visible API since adding [SecurityCritical]
// on "new" visible API would introduce incompatibility (so this needs
// to be reviewed).
if (method.IsVisible ())
//.........这里部分代码省略.........
示例4: DetectSafeCriticalMethod
static void DetectSafeCriticalMethod (MethodDefinition method)
{
// we consider all SafeNativeMethods.* as [SecuritySafeCritical]
// if not then move them into NativeMethods or UnsafeNativeMethods
if (method.IsPInvokeImpl && (method.DeclaringType.Name == "SafeNativeMethods")) {
MarkAsSafeCritical (method);
if (!comments)
return;
Annotate (method, "pinvoke / SafeNativeMethods");
}
// SC code can call SC code
// note: here we use the 'rock' because the [SecurityCritical] attribute
// could be located on the type (or nested type)
if (IsSecurityCritical (method))
return;
// an icall that is part of the visible API is considered as safe critical
if (method.IsInternalCall) {
if (method.IsVisible ()) {
MarkAsSafeCritical (method);
if (!comments)
return;
Annotate (method, "VISIBLE internal call");
} else if (method.IsVirtual) {
MarkAsSafeCritical (method);
if (!comments)
return;
Annotate (method, "virtual internal call");
}
}
if (!method.HasBody)
return;
foreach (Instruction ins in method.Body.Instructions) {
MethodReference mr = (ins.Operand as MethodReference);
if (mr == null)
continue;
MethodDefinition md = mr.Resolve ();
if (md == null) {
// this can occurs for some generated types, like Int[,] where the compiler generates a few methods
continue;
}
// again we use the rock here as we want the final result (not the local attribute)
if (IsSecurityCritical (md)) {
MarkAsSafeCritical (method);
if (!comments)
return;
Annotate (method, String.Format ("{0}method calling [SecurityCritical] {1}",
md.IsVisible () ? "VISIBLE " : String.Empty, md.FullName));
}
}
}
示例5: DetectCriticalMethod
static void DetectCriticalMethod (MethodDefinition method)
{
// p/invoke methods needs to be [SecurityCritical] to be executed,
// unless they are inside a type named "SafeNativeMethods"
bool sc = (method.IsPInvokeImpl && (method.DeclaringType.Name != "SafeNativeMethods"));
if (sc) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, "p/invoke declaration");
}
string comment = CheckVerifiability (method);
if (!String.IsNullOrEmpty (comment)) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, comment);
}
// skip signature check for visible API (we get them from find-sc)
if (!method.IsVisible ()) {
if (method.HasParameters) {
// compilers will add public stuff like: System.Action`1::.ctor(System.Object,System.IntPtr)
if (!method.IsConstructor || (method.DeclaringType as TypeDefinition).BaseType.FullName != "System.MulticastDelegate") {
foreach (ParameterDefinition p in method.Parameters) {
if (!CheckType (p.ParameterType)) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, String.Format ("using '{0}' as a parameter type", p.ParameterType.FullName));
}
}
}
}
TypeReference rtype = method.ReturnType;
if (!CheckType (rtype)) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, String.Format ("using '{0}' as return type", rtype.FullName));
}
}
// check if this method implements an interface where the corresponding member
// is [SecurityCritical]
comment = CheckInterfaces (method);
if (!String.IsNullOrEmpty (comment)) {
MarkAsCritical (method);
if (!comments)
return;
if (method.IsVisible ())
comment = "VISIBLE " + comment;
Annotate (method, comment);
}
sc = IsSecurityCritical (method);
// if we're overriding a [SecurityCritical] method then we must be one too! or
// if we are [SecurityCritical] then the base method needs to be too!
if (method.IsVirtual && !method.IsAbstract) {
TypeReference tr = method.DeclaringType.BaseType;
if (tr != null) {
TypeDefinition td = tr.Resolve ();
if (td != null) {
foreach (MethodDefinition bm in td.GetMethods ()) {
if (Compare (method, bm)) {
if (!sc) {
if (IsSecurityCritical (bm)) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, String.Format ("{0}[SecurityCritical] required to override '{1}'.",
method.IsVisible () ? "WARNING! New VISIBLE " : String.Empty, bm));
}
} else {
if (!IsSecurityCritical (bm) && bm.Name != "Finalize") {
MarkAsCritical (bm);
if (!comments)
return;
Annotate (bm, String.Format ("{0}base method promoted to [SecurityCritical] because of '{1}'.",
bm.IsVisible () ? "WARNING! New VISIBLE " : String.Empty, method));
}
}
}
}
}
}
} else {
// note: we don't want to break the override rules above (resulting in TypeLoadException)
// an icall that is NOT part of the visible API is considered as critical (like a p/invoke)
if (method.IsInternalCall && !method.IsVisible ()) {
MarkAsCritical (method);
if (!comments)
return;
Annotate (method, "non-visible internal call");
}
}
// if this method is [SecurityCritical] (already or because we determined it should be)
//.........这里部分代码省略.........