public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IFacet facet = null; if (!type.IsInterface && typeof (IViewModel).IsAssignableFrom(type)) { MethodInfo deriveMethod = type.GetMethod("DeriveKeys", new Type[] {}); MethodInfo populateMethod = type.GetMethod("PopulateUsingKeys", new[] {typeof (string[])}); var toRemove = new List<MethodInfo> {deriveMethod, populateMethod}; if (typeof (IViewModelEdit).IsAssignableFrom(type)) { facet = new ViewModelEditFacetConvention(specification); } else if (typeof (IViewModelSwitchable).IsAssignableFrom(type)) { MethodInfo isEditViewMethod = type.GetMethod("IsEditView"); toRemove.Add(isEditViewMethod); facet = new ViewModelSwitchableFacetConvention(specification); } else { facet = new ViewModelFacetConvention(specification); } methodRemover.RemoveMethods(toRemove.ToArray()); } FacetUtils.AddFacet(facet); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IFacet facet = null; if (!type.IsInterface && typeof(IViewModel).IsAssignableFrom(type)) { MethodInfo deriveMethod = type.GetMethod("DeriveKeys", new Type[] {}); MethodInfo populateMethod = type.GetMethod("PopulateUsingKeys", new[] { typeof(string[]) }); var toRemove = new List <MethodInfo> { deriveMethod, populateMethod }; if (typeof(IViewModelEdit).IsAssignableFrom(type)) { facet = new ViewModelEditFacetConvention(specification); } else if (typeof(IViewModelSwitchable).IsAssignableFrom(type)) { MethodInfo isEditViewMethod = type.GetMethod("IsEditView"); toRemove.Add(isEditViewMethod); facet = new ViewModelSwitchableFacetConvention(specification); } else { facet = new ViewModelFacetConvention(specification); } methodRemover.RemoveMethods(toRemove.ToArray()); } FacetUtils.AddFacet(facet); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (typeof(IViewModel).IsAssignableFrom(type)) { IFacet facet; var deriveMethod = type.GetMethod("DeriveKeys", new Type[] { }); var populateMethod = type.GetMethod("PopulateUsingKeys", new[] { typeof(string[]) }); var toRemove = new List <MethodInfo> { deriveMethod, populateMethod }; if (typeof(IViewModelEdit).IsAssignableFrom(type)) { facet = new ViewModelEditFacetConvention(specification); } else if (typeof(IViewModelSwitchable).IsAssignableFrom(type)) { var isEditViewMethod = type.GetMethod("IsEditView"); toRemove.Add(isEditViewMethod); facet = new ViewModelSwitchableFacetConvention(specification); } else { facet = new ViewModelFacetConvention(specification); } methodRemover.RemoveMethods(toRemove.ToArray()); FacetUtils.AddFacet(facet); } return(metamodel); }
public override void Process(IReflector reflector, Type type, IMethodRemover remover, ISpecificationBuilder specification) { var facets = new List<IFacet>(); var methods = new List<MethodInfo>(); MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.CreatedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new CreatedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new CreatedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.PersistingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new PersistingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new PersistingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.PersistedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new PersistedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new PersistedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.UpdatingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new UpdatingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.UpdatedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new UpdatedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.LoadingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new LoadingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.LoadedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new LoadedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.DeletingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new DeletingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.DeletedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new DeletedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.OnUpdatingErrorMethod, typeof (string), new[] {typeof (Exception)}); if (method != null) { methods.Add(method); facets.Add(new OnUpdatingErrorCallbackFacetViaMethod(method, specification)); } else { facets.Add(new OnUpdatingErrorCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.OnPersistingErrorMethod, typeof (string), new[] {typeof (Exception)}); if (method != null) { methods.Add(method); facets.Add(new OnPersistingErrorCallbackFacetViaMethod(method, specification)); } else { facets.Add(new OnPersistingErrorCallbackFacetNull(specification)); } remover.RemoveMethods(methods); FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, Type type, IMethodRemover remover, ISpecificationBuilder specification) { var facets = new List <IFacet>(); var methods = new List <MethodInfo>(); var method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.CreatedMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new CreatedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new CreatedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.PersistingMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new PersistingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new PersistingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.PersistedMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new PersistedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new PersistedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.UpdatingMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new UpdatingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.UpdatedMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new UpdatedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.LoadingMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new LoadingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.LoadedMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new LoadedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.DeletingMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletingCallbackFacetViaMethod(method, specification)); } else { facets.Add(new DeletingCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.DeletedMethod, typeof(void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletedCallbackFacetViaMethod(method, specification)); } else { facets.Add(new DeletedCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.OnUpdatingErrorMethod, typeof(string), new[] { typeof(Exception) }); if (method != null) { methods.Add(method); facets.Add(new OnUpdatingErrorCallbackFacetViaMethod(method, specification, Logger <OnUpdatingErrorCallbackFacetViaMethod>())); } else { facets.Add(new OnUpdatingErrorCallbackFacetNull(specification)); } method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.OnPersistingErrorMethod, typeof(string), new[] { typeof(Exception) }); if (method != null) { methods.Add(method); facets.Add(new OnPersistingErrorCallbackFacetViaMethod(method, specification, Logger <OnPersistingErrorCallbackFacetViaMethod>())); } else { facets.Add(new OnPersistingErrorCallbackFacetNull(specification)); } remover.RemoveMethods(methods); FacetUtils.AddFacets(facets); }
public override bool Process(Type type, IMethodRemover remover, IFacetHolder facetHolder) { var facets = new List<IFacet>(); var methods = new List<MethodInfo>(); MethodInfo method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.CreatedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new CreatedCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new CreatedCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.PersistingMethod, typeof (void), Type.EmptyTypes); MethodInfo oldMethod = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.SavingMethod, typeof (void), Type.EmptyTypes); if (method != null && oldMethod != null) { // cannot have both old and new method types throw new ModelException(Resources.NakedObjects.PersistingSavingError); } if (method == null && oldMethod != null) { Log.WarnFormat("Class {0} still has Saving method - replace with Persisting", type); method = oldMethod; } if (method != null) { methods.Add(method); facets.Add(new PersistingCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new PersistingCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.PersistedMethod, typeof (void), Type.EmptyTypes); oldMethod = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.SavedMethod, typeof (void), Type.EmptyTypes); if (method != null && oldMethod != null) { // cannot have both old and new method types throw new ModelException("Cannot have both Persisted and Saved methods - please remove Saved"); } if (method == null && oldMethod != null) { Log.WarnFormat("Class {0} still has Saved method - replace with Persisted", type.ToString()); method = oldMethod; } if (method != null) { methods.Add(method); facets.Add(new PersistedCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new PersistedCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.UpdatingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatingCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new UpdatingCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.UpdatedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new UpdatedCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new UpdatedCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.LoadingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadingCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new LoadingCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.LoadedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new LoadedCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new LoadedCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.DeletingMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletingCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new DeletingCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.DeletedMethod, typeof (void), Type.EmptyTypes); if (method != null) { methods.Add(method); facets.Add(new DeletedCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new DeletedCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.OnUpdatingErrorMethod, typeof (string), new[] {typeof (Exception)}); if (method != null) { methods.Add(method); facets.Add(new OnUpdatingErrorCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new OnUpdatingErrorCallbackFacetNull(facetHolder)); } method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.OnPersistingErrorMethod, typeof (string), new[] {typeof (Exception)}); if (method != null) { methods.Add(method); facets.Add(new OnPersistingErrorCallbackFacetViaMethod(method, facetHolder)); } else { facets.Add(new OnPersistingErrorCallbackFacetNull(facetHolder)); } remover.RemoveMethods(methods); return FacetUtils.AddFacets(facets); }