コード例 #1
0
        internal static void ReflectMethod(ErrorCollector collector, AstNode where, string type_name, string method_name, int arity, List <MethodInfo> methods, ref bool success)
        {
            var reflected_type = System.Type.GetType(type_name, false);

            if (reflected_type == null)
            {
                success = false;
                collector.ReportRawError(where, "No such type " + type_name + " found. Perhaps you are missing an assembly reference.");
            }
            else
            {
                foreach (var method in reflected_type.GetMethods())
                {
                    var adjusted_arity = method.GetParameters().Length + (method.IsStatic ? 0 : 1);
                    if (method.Name == method_name && adjusted_arity == arity && !method.IsGenericMethod && !method.IsGenericMethodDefinition && AllInParameteres(method))
                    {
                        methods.Add(method);
                    }
                }
                if (methods.Count == 0)
                {
                    success = false;
                    collector.ReportRawError(where, "The type " + type_name + " has no public method named " + method_name + " which takes " + arity + " parameters.");
                }
            }
        }
コード例 #2
0
        internal static FieldInfo ReflectField(ErrorCollector collector, AstNode where, string type_name, string field_name, ref bool success)
        {
            var reflected_type = System.Type.GetType(type_name, false);

            if (reflected_type == null)
            {
                success = false;
                collector.ReportRawError(where, "No such type " + type_name + " found. Perhaps you are missing an assembly reference.");
                return(null);
            }
            var field = reflected_type.GetField(field_name);

            if (field == null || !field.IsPublic)
            {
                success = false;
                collector.ReportRawError(where, "The type " + type_name + " does not contain a public static field " + field_name + ".");
            }
            return(field);
        }