private static MethodDefinition FindMethodIn(MethodDefinition method, TypeDefinition typeDef) { return(typeDef.Methods.Cast <MethodDefinition>().FirstOrDefault(bm => MethodDefinitionComparator.Compare(method, bm))); }
static void ProcessMethod(MethodDefinition method) { string comment = null; // All p/invoke methods needs to be [SecurityCritical] to be executed bool sc = method.IsPInvokeImpl; if (sc) { comment = "p/invoke declaration"; } if (!sc) { comment = CheckVerifiability(method); sc = !String.IsNullOrEmpty(comment); } if (!sc) { sc = !IsMethodSignatureSafe(method, ref comment); } // check if this method implements an interface where the corresponding member // is [SecurityCritical] TypeDefinition type = method.DeclaringType; if (!sc && !method.IsConstructor && type.HasInterfaces) { foreach (TypeReference intf in type.Interfaces) { TypeDefinition td = intf.Resolve(); if (td == null || !td.HasMethods) { continue; } foreach (MethodDefinition im in td.Methods) { if (IsSecurityCritical(im)) { if (MethodDefinitionComparator.Compare(method, im)) { sc = true; comment = String.Format("implements '{0}'.", im); } } } } } if (!method.IsVirtual) { // 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) { sc = true; comment = "internal call"; } } if (sc && !methods.ContainsKey(method)) { // note: add a warning on visible API since adding [SecurityCritical] // on "new" visible API would introduce incompatibility (so this needs // to be reviewed). methods.Add(method, comment); } }