示例#1
0
	public MetaRuleBuilder (string name, NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attr)
	{
	    rb = new RuleBuilder (name, ns, loc, attr);
	    tmpl = new RuleTemplateBuilder (name + "RTemplate", rb, ns, loc, attr);

	    ns.AddMetaRule (this);
	    BaseClass = RuleType;
	}
示例#2
0
        public MetaRuleBuilder(string name, NamespaceBuilder ns, CodeLinePragma loc, TypeAttributes attr)
        {
            rb   = new RuleBuilder(name, ns, loc, attr);
            tmpl = new RuleTemplateBuilder(name + "RTemplate", rb, ns, loc, attr);

            ns.AddMetaRule(this);
            BaseClass = RuleType;
        }
示例#3
0
        public UserType ResolveBoundRuleType(TypeResolveContext trc, bool errors)
        {
            if (!resolved)
            {
                if (errors)
                {
                    throw new InvalidOperationException();
                }
                return(null);
            }

            UserType ret;

            if (IsUser)
            {
                // User type. Use our lookup tables

                RuleTemplateBuilder rtb = trc.Driver.GetUserTypeItem((string)t) as RuleTemplateBuilder;

                if (errors && rtb == null)
                {
                    throw ExHelp.App("Expected a rule template but got {0} for {1}",
                                     trc.Driver.GetUserTypeItem((string)t), this);
                }

                ret = new UserType(rtb.Rule.FullName);
            }
            else
            {
                // System type. Use reflection.

                Type type = (Type)t;

                object[] attrs = type.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                if (errors && attrs.Length == 0)
                {
                    throw ExHelp.App("Expected type {0} to have a RuleBindingAttribute " +
                                     "but it didn't. This type is not allowed to be a rule baseclass.", type);
                }

                ret = new UserType(((RuleBindingAttribute)attrs[0]).RuleType);
            }

            if (ret.Resolve(trc, errors))
            {
                if (errors)
                {
                    throw ExHelp.App("Failed to resolve bound rule type {0}", ret);
                }
                return(null);
            }

            return(ret);
        }