Пример #1
0
        /// <summary>
        /// Resolve the type we are casting to
        /// </summary>
        /// <param name="destTypeParts"></param>
        /// <param name="services"></param>
        /// <returns></returns>
        private static Type GetDestType(string[] destTypeParts, IServiceProvider services)
        {
            ExpressionContext context = (ExpressionContext)services.GetService(typeof(ExpressionContext));

            Type t = null;

            // Try to find a builtin type with the name
            if (destTypeParts.Length == 1)
            {
                t = ExpressionImports.GetBuiltinType(destTypeParts[0]);
            }

            if ((t != null))
            {
                return(t);
            }

            // Try to find the type in an import
            t = context.Imports.FindType(destTypeParts);

            if ((t != null))
            {
                return(t);
            }

            return(null);
        }
Пример #2
0
        public static void AddInstance(this ExpressionImports imports, object target, string @namespace, Func <MethodInfo, bool> selector = null, BindingFlags?flags = null)
        {
            if (target == null)
            {
                return;
            }

            imports.AddType(InstanceToStaticWrapper.Wrap(target), @namespace);
        }
Пример #3
0
        public ICollection <string> GetIdentifiers(ExpressionContext context)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            ExpressionImports           ei   = context.Imports;

            foreach (string identifier in _myIdentifiers.Values)
            {
                // Skip names registered as namespaces
                if (ei.HasNamespace(identifier) == true)
                {
                    continue;
                }
                else if (context.Variables.ContainsKey(identifier) == true)
                {
                    // Identifier is a variable
                    continue;
                }

                // Get only the unique values
                dict[identifier] = null;
            }

            return(dict.Keys);
        }