private Tuple <IActionSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> > FindActionMethods(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var actionSpecs = new List <IActionSpecImmutable>(); var actions = facetFactorySet.FindActions(methods.Where(m => m != null).ToArray(), reflector.ClassStrategy).Where(a => !facetFactorySet.Filters(a, reflector.ClassStrategy)).ToArray(); methods = methods.Except(actions).ToArray(); // ReSharper disable once ForCanBeConvertedToForeach // kepp for look as actions are nulled out within loop for (int i = 0; i < actions.Length; i++) { MethodInfo actionMethod = actions[i]; // actions are potentially being nulled within this loop if (actionMethod != null) { string fullMethodName = actionMethod.Name; Type[] parameterTypes = actionMethod.GetParameters().Select(parameterInfo => parameterInfo.ParameterType).ToArray(); // build action & its parameters // if static leave to facet to sort out return type if (actionMethod.ReturnType != typeof(void) && !actionMethod.IsStatic) { metamodel = reflector.LoadSpecification(actionMethod.ReturnType, metamodel).Item2; } IIdentifier identifier = new IdentifierImpl(FullName, fullMethodName, actionMethod.GetParameters().ToArray()); //IActionParameterSpecImmutable[] actionParams = parameterTypes. // Select(pt => ImmutableSpecFactory.CreateActionParameterSpecImmutable(reflector.LoadSpecification<IObjectSpecImmutable>(pt, metamodel), identifier)).ToArray(); var actionParams = new List <IActionParameterSpecImmutable>(); foreach (var pt in parameterTypes) { var result = reflector.LoadSpecification(pt, metamodel); metamodel = result.Item2; var ospec = result.Item1 as IObjectSpecImmutable; var actionSpec = ImmutableSpecFactory.CreateActionParameterSpecImmutable(ospec, identifier); actionParams.Add(actionSpec); } var action = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, spec, actionParams.ToArray()); // Process facets on the action & parameters metamodel = facetFactorySet.Process(reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions, metamodel); for (int l = 0; l < actionParams.Count; l++) { metamodel = facetFactorySet.ProcessParams(reflector, actionMethod, l, actionParams[l], metamodel); } actionSpecs.Add(action); } } return(new Tuple <IActionSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> >(actionSpecs.ToArray(), metamodel)); }
private (IActionSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder>) FindActionMethods(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var actionSpecs = new List <IActionSpecImmutable>(); var actions = FacetFactorySet.FindActions(methods.Where(m => m != null).ToArray(), reflector.ClassStrategy).Where(a => !FacetFactorySet.Filters(a, reflector.ClassStrategy)).ToArray(); methods = methods.Except(actions).ToArray(); // ReSharper disable once ForCanBeConvertedToForeach // keep a "for loop" as actions are nulled out within loop for (var i = 0; i < actions.Length; i++) { var actionMethod = actions[i]; // actions are potentially being nulled within this loop if (actionMethod != null) { var fullMethodName = actionMethod.Name; var parameterTypes = actionMethod.GetParameters().Select(parameterInfo => parameterInfo.ParameterType).ToArray(); // build action & its parameters if (actionMethod.ReturnType != typeof(void)) { (_, metamodel) = reflector.LoadSpecification(actionMethod.ReturnType, metamodel); } IIdentifier identifier = new IdentifierImpl(FullName, fullMethodName, actionMethod.GetParameters().ToArray()); var actionParams = new List <IActionParameterSpecImmutable>(); foreach (var pt in parameterTypes) { IObjectSpecBuilder oSpec; (oSpec, metamodel) = reflector.LoadSpecification <IObjectSpecBuilder>(pt, metamodel); var actionSpec = ImmutableSpecFactory.CreateActionParameterSpecImmutable(oSpec, identifier); actionParams.Add(actionSpec); } var action = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, spec, actionParams.ToArray()); // Process facets on the action & parameters metamodel = FacetFactorySet.Process(reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions, metamodel); for (var l = 0; l < actionParams.Count; l++) { metamodel = FacetFactorySet.ProcessParams(reflector, actionMethod, l, actionParams[l], metamodel); } actionSpecs.Add(action); } } return(actionSpecs.ToArray(), metamodel); }
private static IActionSpecImmutable CreateHolderWithParms() { var tps1 = new Mock <IObjectSpecImmutable>(); //"System.Int32" var tps2 = new Mock <IObjectSpecImmutable>(); //System.Int64" var tps3 = new Mock <IObjectSpecImmutable>(); //"System.Int64" var param1 = ImmutableSpecFactory.CreateActionParameterSpecImmutable(tps1.Object, null); var param2 = ImmutableSpecFactory.CreateActionParameterSpecImmutable(tps2.Object, null); var param3 = ImmutableSpecFactory.CreateActionParameterSpecImmutable(tps3.Object, null); var parms = new[] { param1, param2, param3 }; var tpi = new Mock <IIdentifier>(); // ""action" var id = tpi.Object; return(ImmutableSpecFactory.CreateActionSpecImmutable(id, null, parms)); }
private IActionSpecImmutable[] FindActionMethods(ITypeSpecImmutable spec) { var actionSpecs = new List <IActionSpecImmutable>(); var actions = FacetFactorySet.FindActions(methods.Where(m => m != null).ToArray(), reflector.ClassStrategy).Where(a => !FacetFactorySet.Filters(a, reflector.ClassStrategy)).ToArray(); methods = methods.Except(actions).ToArray(); // ReSharper disable once ForCanBeConvertedToForeach // kepp for look as actions are nulled out within loop for (int i = 0; i < actions.Length; i++) { MethodInfo actionMethod = actions[i]; // actions are potentially being nulled within this loop if (actionMethod != null) { string fullMethodName = actionMethod.Name; Type[] parameterTypes = actionMethod.GetParameters().Select(parameterInfo => parameterInfo.ParameterType).ToArray(); // build action & its parameters if (actionMethod.ReturnType != typeof(void)) { reflector.LoadSpecification(actionMethod.ReturnType); } IIdentifier identifier = new IdentifierImpl(FullName, fullMethodName, actionMethod.GetParameters().ToArray()); IActionParameterSpecImmutable[] actionParams = parameterTypes.Select(pt => ImmutableSpecFactory.CreateActionParameterSpecImmutable(reflector.LoadSpecification <IObjectSpecImmutable>(pt), identifier)).ToArray(); var action = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, spec, actionParams); // Process facets on the action & parameters FacetFactorySet.Process(reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions); for (int l = 0; l < actionParams.Length; l++) { FacetFactorySet.ProcessParams(reflector, actionMethod, l, actionParams[l]); } actionSpecs.Add(action); } } return(actionSpecs.ToArray()); }