示例#1
0
        protected string DynamicCompile(string name, AbstractClause clause)
        {
            MethodInfo methodInfo = this.GetType()
                                    .GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance);

            if (methodInfo == null)
            {
                throw new Exception($"Failed to locate a compiler for {name}.");
            }

            var isGeneric = clause.GetType()
#if FEATURE_TYPE_INFO
                            .GetTypeInfo()
#endif
                            .IsGenericType;

            if (isGeneric && methodInfo.GetGenericArguments().Any())
            {
                var args = clause.GetType().GetGenericArguments();
                methodInfo = methodInfo.MakeGenericMethod(args);
            }

            var result = methodInfo.Invoke(this, new object[] { clause });

            return(result as string);
        }
示例#2
0
        /// <summary>
        /// Add a component clause to the factory.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="clause"></param>
        /// <param name="engineCode"></param>
        /// <returns></returns>
        public Q AddComponent(string component, AbstractClause clause, string engineCode = null)
        {
            if (engineCode == null)
            {
                engineCode = EngineScope;
            }

            clause.Engine    = engineCode;
            clause.Component = component;
            Clauses.Add(clause);

            return(instance);
        }
示例#3
0
        protected string DynamicCompile(string name, AbstractClause clause)
        {
            MethodInfo methodInfo = this.GetType()
                                    .GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance);

            if (methodInfo == null)
            {
                throw new Exception($"Failed to locate a compiler for {name}.");
            }

            if (methodInfo.GetGenericArguments().Any() && clause.GetType().GetTypeInfo().IsGenericType)
            {
                methodInfo = methodInfo.MakeGenericMethod(clause.GetType().GenericTypeArguments.First());
            }

            var result = methodInfo.Invoke(this, new object[] { clause });

            return(result as string);
        }
示例#4
0
 private InvalidCastException InvalidClauseException(string section, AbstractClause clause)
 {
     return(new InvalidCastException($"Invalid type \"{clause.GetType().Name}\" provided for the \"{section}\" clause."));
 }
示例#5
0
 public AbstractClause(AbstractClause other)
 {
     Engine    = other.Engine;
     Component = other.Component;
 }