private List <SafeControlDefinition> BuildSafeControlsWithTypes(AssemblyDefinition assembly) { // Get the System.Web.UI.Control type. Type controlType = typeof(Control); List <SafeControlDefinition> safeControlList = new List <SafeControlDefinition>(); string assemblyName = assembly.Name.FullName; foreach (TypeDefinition classType in assembly.MainModule.Types) { if (!"<Module>".Equals(classType.Name, StringComparison.InvariantCultureIgnoreCase)) { if (IncludeType(assembly, classType, controlType)) { SafeControlDefinition safeControl = new SafeControlDefinition(); safeControl.SafeSpecified = true; safeControl.Assembly = assemblyName; safeControl.Namespace = classType.Namespace; safeControl.Safe = TrueFalseMixed.True; safeControl.TypeName = classType.Name; safeControlList.Add(safeControl); } } } return(safeControlList); }
/// <summary> /// Builds the safe controls objects. /// </summary> /// <returns>The safe control list.</returns> public SafeControlDefinition[] BuildSafeControlDefinition(AssemblyDefinition assembly, SafeControlDefinition[] existingSafeControls) { List <SafeControlDefinition> safeControlList = null; // Ensure that the existingSafeControls are not null existingSafeControls = existingSafeControls != null ? existingSafeControls : new SafeControlDefinition[] { }; // If a parameter is set to specify that the types should be written, then if (ExpandTypes) { safeControlList = BuildSafeControlsWithTypes(assembly); } else { safeControlList = BuildSafeControlsWithNamespaces(assembly); } if (safeControlList.Count == 0) { return(null); } foreach (SafeControlDefinition existingItem in existingSafeControls) { if (!safeControlList.Exists(p => SafeControlDefinition.IsMatch(p, existingItem))) { safeControlList.Add(existingItem); } } Log.Verbose("SafeControls added: " + safeControlList.Count); return(safeControlList.ToArray()); }
public static bool IsMatch(SafeControlDefinition source, SafeControlDefinition target) { bool result = source.Assembly == target.Assembly && source.Namespace == target.Namespace && source.TypeName == target.TypeName; return(result); }
/// <summary> /// Create the SafeControls with namespaces /// </summary> /// <param name="assembly"></param> /// <returns></returns> private List <SafeControlDefinition> BuildSafeControlsWithNamespaces(AssemblyDefinition assembly) { // Get the System.Web.UI.Control type. Type controlType = typeof(Control); List <SafeControlDefinition> safeControlList = new List <SafeControlDefinition>(); string assemblyName = assembly.Name.FullName; Hashtable coll = new Hashtable(); foreach (TypeDefinition classType in assembly.MainModule.Types) { if (!"<Module>".Equals(classType.Name, StringComparison.InvariantCultureIgnoreCase)) { if (IncludeType(assembly, classType, controlType)) { string key = (String.IsNullOrEmpty(classType.Namespace)) ? EMPTYNAMESPACE : classType.Namespace; coll[key] = true; } } } foreach (string nameSpace in coll.Keys) { // otherwise just write the asteriks SafeControlDefinition safeControl = new SafeControlDefinition(); safeControl.SafeSpecified = true; safeControl.Assembly = assemblyName; safeControl.Namespace = (nameSpace.Equals(EMPTYNAMESPACE)) ? "" : nameSpace; safeControl.Safe = TrueFalseMixed.True; safeControl.TypeName = "*"; safeControlList.Add(safeControl); } return(safeControlList); }