public virtual bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue)
        {
            TypeReference valueType = type.Reference;

            if (v == null)
            {
                returnvalue = "null";
                return(true);
            }
            if (valueType.FullName == "System.Type")
            {
                var vTypeRef = v as TypeReference;
                if (vTypeRef != null)
                {
                    returnvalue = "typeof(" + NativeTypeManager.GetTranslatedName(vTypeRef) + ")";  // TODO: drop NS handling
                }
                else
                {
                    returnvalue = "typeof(" + v.ToString() + ")";
                }

                return(true);
            }
            if (valueType.FullName == "System.String")
            {
                returnvalue = "\"" + v.ToString() + "\"";
                return(true);
            }
            if (valueType.FullName == "System.Char")
            {
                returnvalue = "'" + v.ToString() + "'";
                return(true);
            }
            if (v is Boolean)
            {
                returnvalue = (bool)v ? "true" : "false";
                return(true);
            }

            TypeDefinition valueDef = type.Definition;

            if (valueDef == null || !valueDef.IsEnum)
            {
                returnvalue = v.ToString();
                return(true);
            }

            string typename = MDocUpdater.GetDocTypeFullName(valueType);
            var    values   = MDocUpdater.GetEnumerationValues(valueDef);
            long   c        = MDocUpdater.ToInt64(v);

            if (values.ContainsKey(c))
            {
                returnvalue = typename + "." + values[c];
                return(true);
            }

            returnvalue = null;
            return(false);
        }
Example #2
0
        public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue)
        {
            TypeReference  valueType = type.Reference;
            string         typename  = MDocUpdater.GetDocTypeFullName(valueType);
            TypeDefinition valueDef  = type.Definition;

            if (typename.Contains("ObjCRuntime.Platform") && valueDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.FlagsAttribute"))
            {
                var  values = MDocUpdater.GetEnumerationValues(valueDef);
                long c      = MDocUpdater.ToInt64(v);

                returnvalue = Format(c, values, typename);
                return(true);
            }

            returnvalue = null;
            return(false);
        }
        public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue)
        {
            TypeReference  valueType = type.Reference;
            TypeDefinition valueDef  = type.Definition;

            if (valueDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.FlagsAttribute"))
            {
                string typename = MDocUpdater.GetDocTypeFullName(valueType);
                var    values   = MDocUpdater.GetEnumerationValues(valueDef);
                long   c        = MDocUpdater.ToInt64(v);
                returnvalue = string.Join(" | ",
                                          (from i in values.Keys
                                           where (c & i) == i && i != 0
                                           select typename + "." + values[i])
                                          .DefaultIfEmpty(c.ToString()).ToArray());

                return(true);
            }

            returnvalue = null;
            return(false);
        }