コード例 #1
0
ファイル: NameLookupContext.cs プロジェクト: emtees/old-code
	public void UseStructure (StructureTemplate st)
	{
	    Type stype = st.GetType ();

	    known_structs[stype] = st;

	    UseRawNamespace (stype.Namespace);
	}
コード例 #2
0
ファイル: BundleManagerBase.cs プロジェクト: retahc/old-code
        // Rule template helpers

        public bool GetTemplateForRule(string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
        {
            ttmpl = null;

            StructureTemplate stmpl = GetNamespaceTemplate(ns, log);

            if (stmpl == null || !sused[ns])
            {
                log.Error(9999, "Trying to use structure template of namespace " +
                          ns + ", but either it wasn't defined or it hasn't been " +
                          "initialized yet.", null);
                return(true);
            }

            // See if we can find a type that has a StructureBinding to tmpl
            // and a RuleBinding to rtype.

            string pns = MBuildPrefix + ns;
            Type   ttype = null, stype = stmpl.GetType();

            foreach (Assembly assy in BundleAssemblies)
            {
                foreach (Type t in assy.GetExportedTypes())
                {
                    if (t.Namespace != pns)
                    {
                        continue;
                    }

                    if (!t.IsSubclassOf(typeof(TargetTemplate)))
                    {
                        continue;
                    }

                    object[] attrs = t.GetCustomAttributes(typeof(StructureBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    StructureBindingAttribute sba = (StructureBindingAttribute)attrs[0];

                    if (sba.StructureType == null)
                    {
                        continue;
                    }

                    if (!sba.StructureType.Equals(stype))
                    {
                        continue;
                    }

                    attrs = t.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    if (!((RuleBindingAttribute)attrs[0]).RuleType.Equals(rtype))
                    {
                        continue;
                    }

                    if (ttype != null)
                    {
                        log.Warning(9999, "Two hits for rule template: " + ttype.ToString() +
                                    " and " + t.ToString(), rtype.ToString());
                    }

                    ttype = t;
                }
            }

            if (ttype != null)
            {
                ttmpl = (TargetTemplate)Activator.CreateInstance(ttype, stmpl);
            }

            return(false);
        }