Пример #1
0
        private static IEnumerable <XObject> GenerateAttributeArgument(IProcessingContext context,
                                                                       CustomAttributeTypedArgument cata)
        {
            // TODO this needs to be cleaned up, and fixed
            context.AddReference(AssetIdentifier.FromMemberInfo(cata.ArgumentType));
            yield return(new XAttribute("type", AssetIdentifier.FromMemberInfo(cata.ArgumentType)));

            if (cata.ArgumentType.IsEnum)
            {
                if (
                    cata.ArgumentType.GetCustomAttributesData().Any(
                        ca =>
                        ca.Constructor.DeclaringType ==
                        typeof(FlagsAttribute)))
                {
                    string   flags = Enum.ToObject(cata.ArgumentType, cata.Value).ToString();
                    string[] parts = flags.Split(',');

                    yield return
                        (new XElement("literal",
                                      new XAttribute("value", cata.Value),
                                      Array.ConvertAll(parts,
                                                       s => new XElement("flag", new XAttribute("value", s.Trim())))));
                }
                else
                {
                    string value = Enum.GetName(cata.ArgumentType, cata.Value);
                    if (value != null)
                    {
                        yield return(new XElement("literal", new XAttribute("value", value)));
                    }

                    yield return(new XElement("literal", new XAttribute("value", cata.Value)));
                }
            }
            else if (cata.ArgumentType == typeof(Type))
            {
                XElement tmp = new XElement("tmp");
                DocGenerator.GenerateTypeRef(context.Clone(tmp), (Type)cata.Value, "value");
                yield return(tmp.Attribute("value"));

                foreach (XElement xElement in tmp.Elements())
                {
                    yield return(xElement);
                }
            }
            else // TODO fix how this encodes unprintable characters
            {
                yield return(new XAttribute("value", cata.Value.ToString().Replace("\0", "\\0")));
            }
        }