/// <summary> /// Initializes a new instance of the <see cref="CodeItemProperty" /> class. /// </summary> public CodeItemProperty() { // Make exceptions for explicit interface implementations - which report private access // but really do not have a meaningful access level. _Access = LazyTryDefault( () => CodeProperty != null && !IsExplicitInterfaceImplementation ? CodeProperty.Access : vsCMAccess.vsCMAccessPublic); _Attributes = LazyTryDefault( () => CodeProperty?.Attributes); _complexity = LazyTryDefault( () => CodeElementHelper.CalculateComplexity(CodeElement)); _DocComment = LazyTryDefault( () => CodeProperty?.DocComment); _isExplicitInterfaceImplementation = LazyTryDefault( () => CodeProperty != null && ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(CodeProperty)); _isIndexer = LazyTryDefault( () => CodeProperty?.Parameters != null && CodeProperty.Parameters.Count > 0); _IsStatic = LazyTryDefault( () => CodeProperty != null && ((CodeProperty.Getter != null && CodeProperty.Getter.IsShared) || (CodeProperty.Setter != null && CodeProperty.Setter.IsShared))); _parameters = LazyTryDefault( () => CodeProperty?.Parameters?.Cast <CodeParameter>().ToList() ?? Enumerable.Empty <CodeParameter>()); _TypeString = LazyTryDefault( () => CodeProperty?.Type?.AsString); }
/// <summary> /// Inserts the explicit access modifiers on methods where they are not specified. /// </summary> /// <param name="methods">The methods.</param> public void InsertExplicitAccessModifiersOnMethods(IEnumerable <CodeItemMethod> methods) { if (!Settings.Default.Cleaning_InsertExplicitAccessModifiersOnMethods) { return; } foreach (var codeFunction in methods.Select(x => x.CodeFunction).Where(y => y != null)) { try { // Skip static constructors - they should not have an access modifier. if (codeFunction.IsShared && codeFunction.FunctionKind == vsCMFunction.vsCMFunctionConstructor) { continue; } // Skip destructors - they should not have an access modifier. if (codeFunction.FunctionKind == vsCMFunction.vsCMFunctionDestructor) { continue; } // Skip explicit interface implementations. if (ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(codeFunction)) { continue; } // Skip methods defined inside an interface. if (codeFunction.Parent is CodeInterface) { continue; } } catch (Exception) { // Skip this method if unable to analyze. continue; } var methodDeclaration = CodeElementHelper.GetMethodDeclaration(codeFunction); // Skip partial methods - access modifier may be specified elsewhere. if (IsKeywordSpecified(methodDeclaration, PartialKeyword)) { continue; } if (!IsAccessModifierExplicitlySpecifiedOnCodeElement(methodDeclaration, codeFunction.Access)) { // Set the access value to itself to cause the code to be added. codeFunction.Access = codeFunction.Access; } } }
/// <summary> /// Initializes a new instance of the <see cref="CodeItemEvent" /> class. /// </summary> public CodeItemEvent() { // Make exceptions for explicit interface implementations - which report private access // but really do not have a meaningful access level. _Access = LazyTryDefault( () => CodeEvent != null && !IsExplicitInterfaceImplementation ? CodeEvent.Access : vsCMAccess.vsCMAccessPublic); _Attributes = LazyTryDefault( () => CodeEvent?.Attributes); _DocComment = LazyTryDefault( () => CodeEvent?.DocComment); _isExplicitInterfaceImplementation = LazyTryDefault( () => CodeEvent != null && ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(CodeEvent)); _IsStatic = LazyTryDefault( () => CodeEvent != null && CodeEvent.IsShared); _TypeString = LazyTryDefault( () => CodeEvent?.Type?.AsString); }
/// <summary> /// Inserts the explicit access modifiers on properties where they are not specified. /// </summary> /// <param name="properties">The properties.</param> public void InsertExplicitAccessModifiersOnProperties(IEnumerable <CodeItemProperty> properties) { if (!Settings.Default.Cleaning_InsertExplicitAccessModifiersOnProperties) { return; } foreach (var codeProperty in properties.Select(x => x.CodeProperty).Where(y => y != null)) { try { // Skip explicit interface implementations. if (ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(codeProperty)) { continue; } // Skip properties defined inside an interface. if (codeProperty.Parent is CodeInterface) { continue; } } catch (Exception) { // Skip this property if unable to analyze. continue; } var propertyDeclaration = CodeElementHelper.GetPropertyDeclaration(codeProperty); if (!IsAccessModifierExplicitlySpecifiedOnCodeElement(propertyDeclaration, codeProperty.Access)) { // Set the access value to itself to cause the code to be added. codeProperty.Access = codeProperty.Access; } } }
/// <summary> /// Initializes a new instance of the <see cref="CodeItemMethod" /> class. /// </summary> public CodeItemMethod() { // Make exceptions for static constructors and explicit interface implementations - // which report private access but really do not have a meaningful access level. _Access = LazyTryDefault( () => CodeFunction != null && !(IsStatic && IsConstructor) && !IsExplicitInterfaceImplementation ? CodeFunction.Access : vsCMAccess.vsCMAccessPublic); _Attributes = LazyTryDefault( () => CodeFunction?.Attributes); _complexity = LazyTryDefault( () => CodeElementHelper.CalculateComplexity(CodeElement)); _DocComment = LazyTryDefault( () => CodeFunction?.DocComment); _isConstructor = LazyTryDefault( () => CodeFunction != null && CodeFunction.FunctionKind == vsCMFunction.vsCMFunctionConstructor); _isDestructor = LazyTryDefault( () => CodeFunction != null && CodeFunction.FunctionKind == vsCMFunction.vsCMFunctionDestructor); _isExplicitInterfaceImplementation = LazyTryDefault( () => CodeFunction != null && ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(CodeFunction)); _IsStatic = LazyTryDefault( () => CodeFunction != null && CodeFunction.IsShared); _overrideKind = LazyTryDefault( () => CodeFunction?.OverrideKind ?? vsCMOverrideKind.vsCMOverrideKindNone); _parameters = LazyTryDefault( () => CodeFunction?.Parameters?.Cast <CodeParameter>().ToList() ?? Enumerable.Empty <CodeParameter>()); _TypeString = LazyTryDefault( () => CodeFunction?.Type?.AsString); }