public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder spec) { var attr = type.GetCustomAttribute<NakedObjectsTypeAttribute>(); if (attr == null) { RemoveExplicitlyIgnoredMembers(type, methodRemover); } else { switch (attr.ReflectionScope) { case ReflectOver.All: RemoveExplicitlyIgnoredMembers(type, methodRemover); break; case ReflectOver.TypeOnlyNoMembers: foreach (MethodInfo method in type.GetMethods()) { methodRemover.RemoveMethod(method); } break; case ReflectOver.ExplicitlyIncludedMembersOnly: foreach (MethodInfo method in type.GetMethods()) { if (method.GetCustomAttribute<NakedObjectsIncludeAttribute>() == null) { methodRemover.RemoveMethod(method); } } break; case ReflectOver.None: throw new ReflectionException("Attempting to introspect a class that has been marked with NakedObjectsType with ReflectOver.None"); default: throw new ReflectionException(String.Format("Unhandled value for ReflectOver: {0}", attr.ReflectionScope)); } } }
/// <summary> /// If no title or ToString can be used then will use Facets provided by /// <see cref="FallbackFacetFactory" /> instead. /// </summary> public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder facetHolder) { IList<MethodInfo> attributedMethods = new List<MethodInfo>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (propertyInfo.GetCustomAttribute<TitleAttribute>() != null) { if (attributedMethods.Count > 0) { Log.Warn("Title annotation is used more than once in " + type.Name + ", this time on property " + propertyInfo.Name + "; this will be ignored"); } attributedMethods.Add(propertyInfo.GetGetMethod()); } } if (attributedMethods.Count > 0) { return FacetUtils.AddFacet(new TitleFacetViaProperty(attributedMethods.First(), facetHolder)); } try { MethodInfo titleMethod = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.TitleMethod, typeof (string), Type.EmptyTypes); IFacet titleFacet = null; if (titleMethod != null) { methodRemover.RemoveMethod(titleMethod); titleFacet = new TitleFacetViaTitleMethod(titleMethod, facetHolder); } MethodInfo toStringMethod = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.ToStringMethod, typeof (string), Type.EmptyTypes); if (toStringMethod != null && !toStringMethod.DeclaringType.Equals(typeof (object))) { methodRemover.RemoveMethod(toStringMethod); } else { // on object do not use toStringMethod = null; } MethodInfo maskMethod = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.ToStringMethod, typeof (string), new[] {typeof (string)}); if (maskMethod != null) { methodRemover.RemoveMethod(maskMethod); } if (titleFacet == null && toStringMethod == null) { // nothing to use return false; } if (titleFacet == null) { titleFacet = new TitleFacetViaToStringMethod(toStringMethod, maskMethod, facetHolder); } return FacetUtils.AddFacet(titleFacet); } catch { return false; } }
/// <summary> /// If no title or ToString can be used then will use Facets provided by /// <see cref="FallbackFacetFactory" /> instead. /// </summary> public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IList<MethodInfo> attributedMethods = new List<MethodInfo>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (propertyInfo.GetCustomAttribute<TitleAttribute>() != null) { if (attributedMethods.Count > 0) { Log.Warn("Title annotation is used more than once in " + type.Name + ", this time on property " + propertyInfo.Name + "; this will be ignored"); } attributedMethods.Add(propertyInfo.GetGetMethod()); } } if (attributedMethods.Count > 0) { // attributes takes priority FacetUtils.AddFacet(new TitleFacetViaProperty(attributedMethods.First(), specification)); return; } try { MethodInfo titleMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.TitleMethod, typeof (string), Type.EmptyTypes); IFacet titleFacet = null; if (titleMethod != null) { methodRemover.RemoveMethod(titleMethod); titleFacet = new TitleFacetViaTitleMethod(titleMethod, specification); } MethodInfo toStringMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof (string), Type.EmptyTypes); if (toStringMethod != null && !(toStringMethod.DeclaringType == typeof (object))) { methodRemover.RemoveMethod(toStringMethod); } else { // on object do not use toStringMethod = null; } MethodInfo maskMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof(string), new[] { typeof(string) }); if (maskMethod != null) { methodRemover.RemoveMethod(maskMethod); } if (titleFacet == null && toStringMethod != null) { titleFacet = new TitleFacetViaToStringMethod(maskMethod, specification); } FacetUtils.AddFacet(titleFacet); } catch (Exception e) { Log.Warn("Unexpected Exception", e); } }
public static void SafeRemoveMethod(this IMethodRemover methodRemover, MethodInfo method) { if (method is not null) { methodRemover?.RemoveMethod(method); } }
public void ProcessSystemType(Type type, IMethodRemover methodRemover, IFacetHolder holder) { InitForType(type); foreach (MethodInfo method in typeToMethods[type]) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (typeof (IEnumerable).IsAssignableFrom(type) && !TypeUtils.IsSystem(type)) { MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.GetEnumeratorMethod, null, Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); } } }
public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) { if (typeof (IEnumerable).IsAssignableFrom(type) && !TypeUtils.IsSystem(type)) { MethodInfo method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.GetEnumeratorMethod, null, Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); } } return false; }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (IsDynamicProxyType(type)) { foreach (MethodInfo method in type.GetMethods().Join(MethodsToRemove, mi => mi.Name, s => s, (mi, s) => mi)) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } } }
public static void FindAndRemoveDisableMethod(IReflector reflector, IList <IFacet> facets, Type type, MethodType methodType, string capitalizedName, ISpecification specification, ILoggerFactory loggerFactory, IMethodRemover methodRemover = null) { var method = FindMethod(reflector, type, methodType, RecognisedMethodsAndPrefixes.DisablePrefix + capitalizedName, typeof(string), Type.EmptyTypes); if (method != null) { methodRemover?.RemoveMethod(method); facets.Add(new DisableForContextFacet(method, specification, loggerFactory.CreateLogger <DisableForContextFacet>())); } }
public void ProcessSystemType(Type type, IMethodRemover methodRemover, ISpecification holder) { InitForType(type); foreach (var method in typeToMethods[type]) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } }
public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) { if (IsDynamicProxyType(type)) { foreach (MethodInfo method in type.GetMethods().Join(methodsToRemove, mi => mi.Name, s => s, (mi, s) => mi)) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } } return false; }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (typeof(IEnumerable).IsAssignableFrom(type) && !TypeUtils.IsSystem(type)) { MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.GetEnumeratorMethod, null, Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); } } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder spec) { var attr = type.GetCustomAttribute <NakedObjectsTypeAttribute>(); if (attr == null) { RemoveExplicitlyIgnoredMembers(type, methodRemover); } else { switch (attr.ReflectionScope) { case ReflectOver.All: RemoveExplicitlyIgnoredMembers(type, methodRemover); break; case ReflectOver.TypeOnlyNoMembers: foreach (MethodInfo method in type.GetMethods()) { methodRemover.RemoveMethod(method); } break; case ReflectOver.ExplicitlyIncludedMembersOnly: foreach (MethodInfo method in type.GetMethods()) { if (method.GetCustomAttribute <NakedObjectsIncludeAttribute>() == null) { methodRemover.RemoveMethod(method); } } break; case ReflectOver.None: throw new ReflectionException("Attempting to introspect a class that has been marked with NakedObjectsType with ReflectOver.None"); default: throw new ReflectionException(String.Format("Unhandled value for ReflectOver: {0}", attr.ReflectionScope)); } } }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (typeof(IEnumerable).IsAssignableFrom(type) && !FasterTypeUtils.IsSystem(type)) { MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.GetEnumeratorMethod, null, Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); } } return(metamodel); }
public static void ProcessSystemType(Type type, IMethodRemover methodRemover, ISpecification holder) { var typeToMethods = new Dictionary <Type, MethodInfo[]>(); InitForType(type, typeToMethods); foreach (var method in typeToMethods[type]) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { try { foreach (string methodName in FixedPrefixes) { MethodInfo methodInfo = FindMethod(reflector, type, MethodType.Object, methodName, typeof (string), Type.EmptyTypes); if (methodInfo != null) { methodRemover.RemoveMethod(methodInfo); } } } catch (Exception e) { Log.Error("Unexpected exception", e); } }
public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder facetHolder) { try { foreach (string methodName in FixedPrefixes) { MethodInfo methodInfo = FindMethod(type, MethodType.Object, methodName, typeof (string), Type.EmptyTypes); if (methodInfo != null) { methodRemover.RemoveMethod(methodInfo); } } return false; } catch { return false; } }
public override ImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (IsDynamicProxyType(type)) { foreach (MethodInfo method in type.GetMethods().Join(MethodsToRemove, mi => mi.Name, s => s, (mi, s) => mi)) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } } return(metamodel); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { try { foreach (string methodName in FixedPrefixes) { MethodInfo methodInfo = FindMethod(reflector, type, MethodType.Object, methodName, typeof(bool), Type.EmptyTypes); if (methodInfo != null) { methodRemover.RemoveMethod(methodInfo); } } } catch (Exception e) { Log.Warn("Unexpected exception", e); } }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { try { foreach (string methodName in FixedPrefixes) { MethodInfo methodInfo = FindMethod(reflector, type, MethodType.Object, methodName, typeof(bool), Type.EmptyTypes); if (methodInfo != null) { methodRemover.RemoveMethod(methodInfo); } } } catch (Exception e) { Log.Error("Unexpected exception", e); } return(metamodel); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var methodPeers = new List<ValidateObjectFacet.NakedObjectValidationMethod>(); MethodInfo[] methods = FindMethods(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ValidatePrefix, typeof (string)); if (methods.Any()) { foreach (MethodInfo method in methods) { ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length >= 2) { bool parametersMatch = parameters.Select(parameter => parameter.Name).Select(name => name[0].ToString(Thread.CurrentThread.CurrentCulture).ToUpper() + name.Substring(1)).All(p => ContainsField(p, type)); if (parametersMatch) { methodPeers.Add(new ValidateObjectFacet.NakedObjectValidationMethod(method)); methodRemover.RemoveMethod(method); } } } } IValidateObjectFacet validateFacet = methodPeers.Any() ? (IValidateObjectFacet) new ValidateObjectFacet(specification, methodPeers) : new ValidateObjectFacetNull(specification); FacetUtils.AddFacet(validateFacet); }
private static void RemoveExplicitlyIgnoredMembers(Type type, IMethodRemover methodRemover) { foreach (MethodInfo method in type.GetMethods().Where(m => m.GetCustomAttribute<NakedObjectsIgnoreAttribute>() != null)) { methodRemover.RemoveMethod(method); } }
/// <summary> /// If no title or ToString can be used then will use Facets provided by /// <see cref="FallbackFacetFactory" /> instead. /// </summary> public override ImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { IList <MethodInfo> attributedMethods = new List <MethodInfo>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (propertyInfo.GetCustomAttribute <TitleAttribute>() != null) { if (attributedMethods.Count > 0) { Log.Warn("Title annotation is used more than once in " + type.Name + ", this time on property " + propertyInfo.Name + "; this will be ignored"); } attributedMethods.Add(propertyInfo.GetGetMethod()); } } if (attributedMethods.Count > 0) { // attributes takes priority FacetUtils.AddFacet(new TitleFacetViaProperty(attributedMethods.First(), specification)); return(metamodel); } try { MethodInfo titleMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.TitleMethod, typeof(string), Type.EmptyTypes); IFacet titleFacet = null; if (titleMethod != null) { methodRemover.RemoveMethod(titleMethod); titleFacet = new TitleFacetViaTitleMethod(titleMethod, specification); } MethodInfo toStringMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof(string), Type.EmptyTypes); if (toStringMethod != null && !(toStringMethod.DeclaringType == typeof(object))) { methodRemover.RemoveMethod(toStringMethod); } else { // on object do not use toStringMethod = null; } MethodInfo maskMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof(string), new[] { typeof(string) }); if (maskMethod != null) { methodRemover.RemoveMethod(maskMethod); } if (titleFacet == null && toStringMethod != null) { titleFacet = new TitleFacetViaToStringMethod(maskMethod, specification); } FacetUtils.AddFacet(titleFacet); } catch (Exception e) { Log.Error("Unexpected Exception", e); } return(metamodel); }
protected void FindAndRemoveDisableMethod(IList<IFacet> facets, IMethodRemover methodRemover, Type type, MethodType methodType, string capitalizedName, Type[] paramTypes, IFacetHolder facetHolder) { MethodInfo method = FindMethodWithOrWithoutParameters(type, methodType, PrefixesAndRecognisedMethods.DisablePrefix + capitalizedName, typeof (string), paramTypes); if (method != null) { methodRemover.RemoveMethod(method); facets.Add(new DisableForContextFacetViaMethod(method, facetHolder)); } }
protected void FindAndRemoveHideMethod(IList<IFacet> facets, IMethodRemover methodRemover, Type type, MethodType methodType, string capitalizedName, Type[] paramTypes, IFacetHolder facetHolder) { MethodInfo method = FindMethodWithOrWithoutParameters(type, methodType, PrefixesAndRecognisedMethods.HidePrefix + capitalizedName, typeof (bool), paramTypes); if (method != null) { methodRemover.RemoveMethod(method); facets.Add(new HideForContextFacetViaMethod(method, facetHolder)); AddOrAddToExecutedWhereFacet(method, facetHolder); } }
protected static void RemoveMethod(IMethodRemover methodRemover, MethodInfo method) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } }
protected void FindAndRemoveHideMethod(IReflector reflector, IList<IFacet> facets, IMethodRemover methodRemover, Type type, MethodType methodType, string capitalizedName, ISpecification specification) { MethodInfo method = FindMethod(reflector, type, methodType, RecognisedMethodsAndPrefixes.HidePrefix + capitalizedName, typeof (bool), Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); facets.Add(new HideForContextFacet(method, specification)); AddOrAddToExecutedWhereFacet(method, specification); } }