public InspectionItem Check(MemberInfo item, object paramValue) { var type = (TypeInfo)item; var value = (bool)paramValue; if (!type.DeclaredConstructors.Any()) { return(InspectionItem.Create(item, true, "This item has no constructors. Skipped")); } foreach (var constructor in type.DeclaredConstructors) { if (value && constructor.IsPublic) { return(InspectionItem.Ok(item)); } else if (!value && constructor.IsPublic) { return(InspectionItem.Create(item, false, $"Type {item.Name} has public constructor")); } } if (!value && type.DeclaredConstructors.All(x => !x.IsPublic)) { return(InspectionItem.Ok(item)); } return(InspectionItem.Create(item, false, $"Type {item.Name} has not valid constructor")); }
public InspectionItem Check(MemberInfo item, object paramValue) { var type = (TypeInfo)item; var value = (DefaultConstructorOptions)paramValue; if (!type.DeclaredConstructors.Any()) { return(InspectionItem.Create(item, true, "This item has no constructors. Skipped")); } foreach (var constructor in type.DeclaredConstructors) { if (constructor.GetParameters().Length == 0) { if (value.IncluePrivate || type.IsAbstract) { return(InspectionItem.Ok(item)); } if (constructor.IsPublic) { return(InspectionItem.Ok(item)); } } } return(InspectionItem.Create(item, false, $"No default constructor found in type {type.Name}")); }
protected InspectionResult InspectUsingParam(MemberInfo member, IParam param) { var inspectionResult = new InspectionResult(); if (param == null) { inspectionResult.AddResult(InspectionItem.Ok(member, "NotSetParam")); return(inspectionResult); } foreach (var item in ((IBuildable)param).Build()) { if (_checkers.ContainsKey(item.Key)) { var result = _checkers[item.Key].Check(member, item.Value); inspectionResult.AddResult(result); } else { throw new InvalidOperationException("Cannot find checker for type " + item.Key); } } return(inspectionResult); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (int)paramValue; if (item.Name.Length > value) { return(InspectionItem.Create(item, false, $"Too long member name {item.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (string[])paramValue; if (!value.Any(x => item.Name.StartsWith(x))) { return(InspectionItem.Create(item, false, $"Wrong member name {item.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (IEnumerable <Type>)paramValue; var type = (TypeInfo)item; if (!value.Any(x => x.IsAssignableFrom(type))) { return(InspectionItem.Create(item, false, $"Type {item.Name} is not implements all interfaces: {string.Join(", ", value.Select(x => x.Name))}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (int)paramValue; var method = (MethodInfo)item; if (method.GetParameters().Any(x => x.Name.Length < value)) { return(InspectionItem.Create(item, false, $"Too short argument name in {item.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (bool)paramValue; if (value && !char.IsLower(item.Name[0])) { return(InspectionItem.Create(item, false, $"Wrong member name {item.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var type = (TypeInfo)item; var value = (int)paramValue; if (type.DeclaredMethods.Count() > value) { return(InspectionItem.Create(item, false, $"Type {item.Name} has too much methods")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var attributes = (IEnumerable <Type>)paramValue; if (item.CustomAttributes.Any(x => attributes.Contains(x.AttributeType))) { return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} has all attributes {string.Join(", ", attributes.Select(x => x.Name))}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (int)paramValue; var method = (MethodInfo)item; if (method.GetParameters().Length > value) { return(InspectionItem.Create(item, false, $"Too much args in method {method.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (bool)paramValue; if (value) { string message = item.DeclaringType != null ? $"Forbidden item {item.Name} in class {item.DeclaringType}" : $"Forbidden item {item.Name}"; return(InspectionItem.Create(item, false, message)); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (string[])paramValue; if (!value.Any(x => item.Name.EndsWith(x))) { string message = item.DeclaringType != null ? $"Wrong member name {item.Name} in class {item.DeclaringType}" : $"Wrong member name {item.Name}"; return(InspectionItem.Create(item, false, message)); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (bool)paramValue; var method = (MethodInfo)item; if (value && method.GetParameters().Any(x => !char.IsLower(x.Name[0]))) { return(InspectionItem.Create(item, false, $"Wrong argument name in {item.Name} in class {item.DeclaringType}")); } else if (!value && method.GetParameters().Any(x => char.IsLower(x.Name[0]))) { return(InspectionItem.Create(item, false, $"Wrong argument name in {item.Name} in class {item.DeclaringType}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (Type)paramValue; var type = (TypeInfo)item; if (type.IsInterface) { return(InspectionItem.Create(item, true, $"Item {value.Name} is interface. Skipped")); } if (!value.IsAssignableFrom(type)) { return(InspectionItem.Create(item, false, $"Type {item.Name} not inherits {value.Name}")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (bool)paramValue; var method = (MethodInfo)item; if (value && method.ReturnType.FullName != "System.Void") { return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} is not void")); } else if (!value && method.ReturnType.FullName == "System.Void") { return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} is void")); } return(InspectionItem.Ok(item)); }
public InspectionItem Check(MemberInfo item, object paramValue) { var value = (PropertyOptions)paramValue; var property = (PropertyInfo)item; if (value.Value) { if (property.GetMethod != null) { if (value.IncludePrivate) { return(InspectionItem.Ok(property)); } if ((property.GetMethod.IsPublic && property.IsPublic()) || (property.GetMethod.IsAssembly && property.IsInternal()) || (property.GetMethod.IsFamily && property.IsProtected())) { return(InspectionItem.Ok(property)); } return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has has only private getter")); } return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has no getter")); } else { if (property.GetMethod == null) { return(InspectionItem.Ok(property)); } else if (property.GetMethod.IsPrivate) { if (value.IncludePrivate) { return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has private getter")); } return(InspectionItem.Ok(property)); } else { return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has getter")); } } }