示例#1
0
        private static void FindEmbedFields(ModuleContainer module, ClassOrStruct cl, List <EmbedData> embeds)
        {
            foreach (var m in cl.Members)
            {
                var f = m as Field;
                if (f == null || f.OptAttributes == null || f.OptAttributes.Attrs.Count == 0)
                {
                    continue;
                }

                if (!(f.TypeExpression is TypeExpression) || f.TypeExpression.Type != module.Compiler.BuiltinTypes.Type)
                {
                    continue;
                }

                Mono.CSharp.Attribute embedAttr = null;
                foreach (var attr in f.OptAttributes.Attrs)
                {
                    if (attr.Name == "Embed")
                    {
                        embedAttr = attr;
                        break;
                    }
                }

                if (embedAttr == null)
                {
                    continue;
                }

                var e = new EmbedData();
                e._index = _embedCount;
                _embedCount++;
                e._className = "__EmbedLoader" + e._index;
                e._field     = f;

                e.source = e.mimeType = e.embedAsCFF = e.fontFamily = e.symbol = "null";

                foreach (NamedArgument arg in embedAttr.NamedArguments)
                {
                    if (!(arg.Expr is StringLiteral))
                    {
                        continue;
                    }
                    var s = ((StringLiteral)(arg.Expr)).GetValueAsLiteral();
                    switch (arg.Name)
                    {
                    case "source": e.source = s; break;

                    case "mimeType": e.mimeType = s; break;

                    case "embedAsCFF": e.embedAsCFF = s; break;

                    case "fontFamily": e.fontFamily = s; break;

                    case "symbol": e.symbol = s; break;
                    }
                }

                embeds.Add(e);
            }
        }