private MethodConfiguration CreateMethodConfiguration(string name, IncrementalizationStrategy strategy, params IncrementalizationStrategy[] allowed)
 {
     var conf = new MethodConfiguration()
     {
         MethodIdentifier = name,
         Strategy = strategy
     };
     conf.AllowedStrategies.AddRange(allowed);
     return conf;
 }
        private MethodConfiguration CreateMethodConfiguration(string name, IncrementalizationStrategy strategy, params IncrementalizationStrategy[] allowed)
        {
            var conf = new MethodConfiguration()
            {
                MethodIdentifier = name,
                Strategy         = strategy
            };

            conf.AllowedStrategies.AddRange(allowed);
            return(conf);
        }
Example #3
0
        protected virtual void RecordExpressionUsage(Expression expression, IEnumerable <ParameterExpression> parameters, bool reversible)
        {
            var expressionConfig = new MethodConfiguration()
            {
                MethodIdentifier = expression.ToString(),
                Strategy         = DefaultStrategy
            };

            expressionConfig.AllowedStrategies.AddRange(GetApplicableStrategies(expression, parameters));
            Configuration.MethodConfigurations.Add(expressionConfig);
        }
        static void Main(string[] args)
        {
            var methodConfig = new MethodConfiguration("ToSimulationVariables", ReturnTypes.Normal, MethodTypes.Dependent);

            var classConfig = new ClassConfiguration("VariableStructureTransformer", ClassTypes.Dependent);
            classConfig.Methods.Add(methodConfig);
            //var classConfig = new ClassConfiguration("FileConfiguration", ClassTypes.Data);

            //classConfig.Properties.Add(new PropertyConfiguration<string>("Name"));
            //classConfig.Properties.Add(new PropertyConfiguration<INsCodeNamespace>("Namespace"));

            var generator = new Generator();

            generator.Generate(classConfig);
        }
Example #5
0
 public static Configuration Clone(this Configuration configuration)
 {
     if (configuration == null) return null;
     var conf = new Configuration();
     foreach (var methodConf in configuration.MethodConfigurations)
     {
         var mc = new MethodConfiguration()
         {
             MethodIdentifier = methodConf.MethodIdentifier,
             Strategy = methodConf.Strategy
         };
         mc.AllowedStrategies.AddRange(methodConf.AllowedStrategies);
         conf.MethodConfigurations.Add(mc);
     }
     return conf;
 }
            internal ParameterConfiguration(MethodConfiguration method, ParameterInfo parameter,
                                            Dictionary <string, ParameterInfo> conflictNameMap, StringComparer comaprer)
            {
                this.ParameterInfo     = parameter;
                this.IsOptional        = parameter.HasDefaultValue;
                this.IsResolveByEngine = method.ServiceProvider.GetRequiredService <AutoResolvedTypes>()
                                         .Contains(parameter.ParameterType);

                var attributes = parameter.GetCustomAttributes().ToArray();

                this.Configure(attributes, parameter.Name);
                this._nameSet = new HashSet <string>(this.Names);
                foreach (var name in this._nameSet)
                {
                    if (conflictNameMap.TryGetValue(name, out var p))
                    {
                        var msg = new StringBuilder()
                                  .AppendLine(GetErrorHeader(parameter))
                                  .AppendLine($"   Name <{name}> is Conflict with Another Parameter <{p.Name}>.");
                        throw new InvalidOperationException(msg.ToString());
                    }
                    conflictNameMap.Add(name, parameter);
                }

                IValueConverter GetValueConverter(Type type)
                {
                    Type t = null;

                    if (type.GetTypeInfo().IsEnum)
                    {
                        t = typeof(EnumConverter <>).FastMakeGenericType(type);
                    }
                    if (t == null)
                    {
                        t = typeof(Converters.IValueConverter <>).FastMakeGenericType(type);
                    }
                    var converter = method.ServiceProvider.GetService(t);

                    if (converter == null)
                    {
                        var msg = new StringBuilder()
                                  .AppendLine(GetErrorHeader(parameter))
                                  .AppendLine($"    convert string to {this.ParameterInfo.ParameterType.Name} is NOT supported.");
                        throw new InvalidOperationException(msg.ToString());
                    }
                    return((IValueConverter)converter);
                }

                if (this.ParameterInfo.ParameterType.IsArray)
                {
                    this.IsArray          = true;
                    this.ArrayElementType = this.ParameterInfo.ParameterType.GetElementType();
                    this.ValueConverter   = GetValueConverter(this.ArrayElementType);
                }
                else
                {
                    if (!this.IsResolveByEngine)
                    {
                        this.ValueConverter = GetValueConverter(this.ParameterInfo.ParameterType);
                    }

                    if (this.ParameterInfo.ParameterType == typeof(bool))
                    {
                        var configurator = new BooleanParameterConfigurator(comaprer);
                        attributes.OfType <IConfigureableAttribute <IBooleanParameterConfigurator> >()
                        .ForEach(z => z.Apply(configurator));
                        var boolMap = configurator.CreateMap();

                        if (this.ValueConverter != null)
                        {
                            this.ValueConverter = new MapedValueConverter(boolMap, this.ValueConverter);
                        }
                    }
                }
            }
 public MethodAcessibilityOptions(MethodConfiguration config)
 {
     this.config = config;
 }
Example #8
0
        /// <summary>
        /// Returns the advices for this invocation
        /// </summary>
        /// <returns></returns>
        public IList <ISolidProxyInvocationAdvice <TObject, TMethod, TAdvice> > GetSolidInvocationAdvices()
        {
            lock (_mutex)
            {
                if (_advices != null)
                {
                    return(_advices);
                }
                var stepTypes = MethodConfiguration.GetSolidInvocationAdviceTypes();
                var sp        = ProxyConfiguration.SolidProxyConfigurationStore.ServiceProvider;

                //
                // create advices
                //
                _advices = stepTypes.Select(t =>
                {
                    if (t.IsGenericTypeDefinition)
                    {
                        switch (t.GetGenericArguments().Length)
                        {
                        case 1:
                            t = t.MakeGenericType(new[] { typeof(TObject) });
                            break;

                        case 2:
                            t = t.MakeGenericType(new[] { typeof(TObject), typeof(TMethod) });
                            break;

                        case 3:
                            t = t.MakeGenericType(new[] { typeof(TObject), typeof(TMethod), typeof(TAdvice) });
                            break;

                        default:
                            throw new Exception("Cannot create handler.");
                        }
                    }

                    var step = (ISolidProxyInvocationAdvice <TObject, TMethod, TAdvice>)sp.GetService(t);
                    if (step == null)
                    {
                        throw new Exception($"Advice not registered in service provider:{t.FullName}");
                    }
                    return(step);
                }).ToList();

                _advices = new ReadOnlyCollection <ISolidProxyInvocationAdvice <TObject, TMethod, TAdvice> >(_advices);

                //
                // configure the advices - remove the ones that return false
                // in config method. Do this in reverse order - thus removing
                // the implementation advice before any other advice is configured.
                // This lets the other advices determine if an implementation exists
                // based on if the implementation advice exists.
                //
                foreach (var advice in _advices.Reverse())
                {
                    if (!SolidConfigurationHelper.ConfigureAdvice(advice, this))
                    {
                        _advices = new ReadOnlyCollection <ISolidProxyInvocationAdvice <TObject, TMethod, TAdvice> >(_advices.Where(o => o != advice).ToList());
                    }
                }
                return(_advices);
            }
        }