Ejemplo n.º 1
0
        /// <summary>
        /// ToString()
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = ObjectPools.AllocStringBuilder();

            sb.Append('[');
            sb.Append(AttributeType.FullName);
            sb.Append('(');
            bool comma = false;

            foreach (var arg in ConstructorArguments)
            {
                if (comma)
                {
                    sb.Append(", ");
                }
                comma = true;
                sb.Append(arg.ToString());
            }
            foreach (var arg in NamedArguments)
            {
                if (comma)
                {
                    sb.Append(", ");
                }
                comma = true;
                sb.Append(arg.ToString());
            }
            sb.Append(")]");
            return(ObjectPools.FreeAndToString(ref sb));
        }
Ejemplo n.º 2
0
        public static string Format(string name, Version version, string culture, byte[] publicKeyOrToken, DmdAssemblyNameFlags attributes, bool isPublicKeyToken)
        {
            var sb = ObjectPools.AllocStringBuilder();

            Format(sb, name, version, culture, publicKeyOrToken, attributes, isPublicKeyToken);
            return(ObjectPools.FreeAndToString(ref sb));
        }
Ejemplo n.º 3
0
 internal string ToString(bool typed)
 {
     if (Value == null)
     {
         return(typed ? "null" : "(" + ArgumentType?.Name + ")null");
     }
     if (ArgumentType.IsEnum)
     {
         return(typed ? Value.ToString() : "(" + ArgumentType.FullName + ")" + Value.ToString());
     }
     if (Value is string s)
     {
         return("\"" + s + "\"");
     }
     if (Value is char c)
     {
         return("'" + c.ToString() + "'");
     }
     if (Value is DmdType type)
     {
         return("typeof(" + type.FullName + ")");
     }
     if (ArgumentType.IsArray)
     {
         var list        = (IList <DmdCustomAttributeTypedArgument>)Value;
         var elementType = ArgumentType.GetElementType();
         var sb          = ObjectPools.AllocStringBuilder();
         sb.Append("new ");
         sb.Append(elementType.IsEnum ? elementType.FullName : elementType.Name);
         sb.Append('[');
         sb.Append(list.Count);
         sb.Append("] { ");
         for (int i = 0; i < list.Count; i++)
         {
             if (i != 0)
             {
                 sb.Append(", ");
             }
             sb.Append(list[i].ToString(elementType != elementType.AppDomain.System_Object));
         }
         sb.Append(" }");
         return(ObjectPools.FreeAndToString(ref sb));
     }
     return(typed ? Value.ToString() : "(" + ArgumentType.Name + ")" + Value.ToString());
 }
Ejemplo n.º 4
0
        bool __CanCastToInterface(DmdType target)
        {
            if (!target.__HasVariance())
            {
                if (HasTypeEquivalence || target.HasTypeEquivalence)
                {
                    if (IsInterface && IsEquivalentTo(target))
                    {
                        return(true);
                    }

                    return(__ImplementsEquivalentInterface(target));
                }

                return(__CanCastToNonVariantInterface(target));
            }
            else
            {
                if (__CanCastByVarianceToInterfaceOrDelegate(target))
                {
                    return(true);
                }

                var hash = GetAllInterfaces(this);
                foreach (var iface in hash)
                {
                    if (iface.__CanCastByVarianceToInterfaceOrDelegate(target))
                    {
                        ObjectPools.Free(ref hash);
                        return(true);
                    }
                }
                ObjectPools.Free(ref hash);
            }
            return(false);
        }
Ejemplo n.º 5
0
 public void Dispose() => ObjectPools.FreeNoToString(ref writer);
Ejemplo n.º 6
0
 DmdMemberFormatter(GlobalFlags flags)
 {
     globalFlags      = flags;
     writer           = ObjectPools.AllocStringBuilder();
     recursionCounter = 0;
 }