Пример #1
0
 private static void AppendValue(StringBuilder sb, CustomAttributeTypedArgument arg)
 {
     if (arg.ArgumentType == arg.ArgumentType.Module.universe.System_String)
     {
         sb.Append('"').Append(arg.Value).Append('"');
     }
     else
     {
         if (arg.ArgumentType.IsEnum)
         {
             sb.Append('(');
             sb.Append(arg.ArgumentType.FullName);
             sb.Append(')');
         }
         sb.Append(arg.Value);
     }
 }
Пример #2
0
        private static object RewrapArray(CustomAttributeTypedArgument arg)
        {
            IList <CustomAttributeTypedArgument> list = arg.Value as IList <CustomAttributeTypedArgument>;

            if (list != null)
            {
                object[] arr = new object[list.Count];
                for (int i = 0; i < arr.Length; i++)
                {
                    // note that CLI spec only allows one dimensional arrays, so we don't need to rewrap the elements
                    arr[i] = list[i].Value;
                }
                return(arr);
            }
            else
            {
                return(arg.Value);
            }
        }
Пример #3
0
 private static void AppendValue(StringBuilder sb, Type type, CustomAttributeTypedArgument arg)
 {
     if (arg.ArgumentType == arg.ArgumentType.Module.universe.System_String)
     {
         sb.Append('"').Append(arg.Value).Append('"');
     }
     else if (arg.ArgumentType.IsArray)
     {
         Type   elementType = arg.ArgumentType.GetElementType();
         string elementTypeName;
         if (elementType.IsPrimitive ||
             elementType == type.Module.universe.System_Object ||
             elementType == type.Module.universe.System_String ||
             elementType == type.Module.universe.System_Type)
         {
             elementTypeName = elementType.Name;
         }
         else
         {
             elementTypeName = elementType.FullName;
         }
         sb.Append("new ").Append(elementTypeName).Append("[").Append(((Array)arg.Value).Length).Append("] { ");
         string sep = "";
         foreach (CustomAttributeTypedArgument elem in (CustomAttributeTypedArgument[])arg.Value)
         {
             sb.Append(sep);
             sep = ", ";
             AppendValue(sb, elementType, elem);
         }
         sb.Append(" }");
     }
     else
     {
         if (arg.ArgumentType != type || (type.IsEnum && !arg.Value.Equals(0)))
         {
             sb.Append('(');
             sb.Append(arg.ArgumentType.FullName);
             sb.Append(')');
         }
         sb.Append(arg.Value);
     }
 }
Пример #4
0
        private static object RewrapArray(Type type, CustomAttributeTypedArgument arg)
        {
            IList <CustomAttributeTypedArgument> list = arg.Value as IList <CustomAttributeTypedArgument>;

            if (list != null)
            {
                Type     elementType = arg.ArgumentType.GetElementType();
                object[] arr         = new object[list.Count];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = RewrapArray(elementType, list[i]);
                }
                if (type == type.Module.universe.System_Object)
                {
                    return(CustomAttributeBuilder.__MakeTypedArgument(arg.ArgumentType, arr));
                }
                return(arr);
            }
            else
            {
                return(arg.Value);
            }
        }
		internal CustomAttributeNamedArgument(MemberInfo member, CustomAttributeTypedArgument value)
		{
			this.member = member;
			this.value = value;
		}
Пример #6
0
        private static CustomAttributeTypedArgument ReadFixedArg(Assembly asm, ByteReader br, Type type)
        {
            Universe u = asm.universe;

            if (type == u.System_String)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadString()));
            }
            else if (type == u.System_Boolean)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte() != 0));
            }
            else if (type == u.System_Char)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadChar()));
            }
            else if (type == u.System_Single)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSingle()));
            }
            else if (type == u.System_Double)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadDouble()));
            }
            else if (type == u.System_SByte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSByte()));
            }
            else if (type == u.System_Int16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt16()));
            }
            else if (type == u.System_Int32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt32()));
            }
            else if (type == u.System_Int64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt64()));
            }
            else if (type == u.System_Byte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte()));
            }
            else if (type == u.System_UInt16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt16()));
            }
            else if (type == u.System_UInt32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt32()));
            }
            else if (type == u.System_UInt64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt64()));
            }
            else if (type == u.System_Type)
            {
                return(new CustomAttributeTypedArgument(type, ReadType(asm, br)));
            }
            else if (type == u.System_Object)
            {
                return(ReadFixedArg(asm, br, ReadFieldOrPropType(asm, br)));
            }
            else if (type.IsArray)
            {
                int length = br.ReadInt32();
                if (length == -1)
                {
                    return(new CustomAttributeTypedArgument(type, null));
                }
                Type elementType = type.GetElementType();
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
                for (int i = 0; i < length; i++)
                {
                    array[i] = ReadFixedArg(asm, br, elementType);
                }
                return(new CustomAttributeTypedArgument(type, array));
            }
            else if (type.IsEnum)
            {
                return(new CustomAttributeTypedArgument(type, ReadFixedArg(asm, br, type.GetEnumUnderlyingTypeImpl()).Value));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Пример #7
0
 internal CustomAttributeNamedArgument(MemberInfo member, CustomAttributeTypedArgument value)
 {
     this.member = member;
     this.value  = value;
 }
		private static object RewrapArray(Type type, CustomAttributeTypedArgument arg)
		{
			IList<CustomAttributeTypedArgument> list = arg.Value as IList<CustomAttributeTypedArgument>;
			if (list != null)
			{
				Type elementType = arg.ArgumentType.GetElementType();
				object[] arr = new object[list.Count];
				for (int i = 0; i < arr.Length; i++)
				{
					arr[i] = RewrapArray(elementType, list[i]);
				}
				if (type == type.Module.universe.System_Object)
				{
					return CustomAttributeBuilder.__MakeTypedArgument(arg.ArgumentType, arr);
				}
				return arr;
			}
			else
			{
				return arg.Value;
			}
		}
		private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteReader br, Type type)
		{
			Universe u = context.universe;
			if (type == u.System_String)
			{
				return new CustomAttributeTypedArgument(type, br.ReadString());
			}
			else if (type == u.System_Boolean)
			{
				return new CustomAttributeTypedArgument(type, br.ReadByte() != 0);
			}
			else if (type == u.System_Char)
			{
				return new CustomAttributeTypedArgument(type, br.ReadChar());
			}
			else if (type == u.System_Single)
			{
				return new CustomAttributeTypedArgument(type, br.ReadSingle());
			}
			else if (type == u.System_Double)
			{
				return new CustomAttributeTypedArgument(type, br.ReadDouble());
			}
			else if (type == u.System_SByte)
			{
				return new CustomAttributeTypedArgument(type, br.ReadSByte());
			}
			else if (type == u.System_Int16)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt16());
			}
			else if (type == u.System_Int32)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt32());
			}
			else if (type == u.System_Int64)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt64());
			}
			else if (type == u.System_Byte)
			{
				return new CustomAttributeTypedArgument(type, br.ReadByte());
			}
			else if (type == u.System_UInt16)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt16());
			}
			else if (type == u.System_UInt32)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt32());
			}
			else if (type == u.System_UInt64)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt64());
			}
			else if (type == u.System_Type)
			{
				return new CustomAttributeTypedArgument(type, ReadType(context, br));
			}
			else if (type == u.System_Object)
			{
				return ReadFixedArg(context, br, ReadFieldOrPropType(context, br));
			}
			else if (type.IsArray)
			{
				int length = br.ReadInt32();
				if (length == -1)
				{
					return new CustomAttributeTypedArgument(type, null);
				}
				Type elementType = type.GetElementType();
				CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
				for (int i = 0; i < length; i++)
				{
					array[i] = ReadFixedArg(context, br, elementType);
				}
				return new CustomAttributeTypedArgument(type, array);
			}
			else if (type.IsEnum)
			{
				return new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value);
			}
			else
			{
				throw new InvalidOperationException();
			}
		}
		private static void AppendValue(StringBuilder sb, Type type, CustomAttributeTypedArgument arg)
		{
			if (arg.ArgumentType == arg.ArgumentType.Module.universe.System_String)
			{
				sb.Append('"').Append(arg.Value).Append('"');
			}
			else if (arg.ArgumentType.IsArray)
			{
				Type elementType = arg.ArgumentType.GetElementType();
				string elementTypeName;
				if (elementType.IsPrimitive
					|| elementType == type.Module.universe.System_Object
					|| elementType == type.Module.universe.System_String
					|| elementType == type.Module.universe.System_Type)
				{
					elementTypeName = elementType.Name;
				}
				else
				{
					elementTypeName = elementType.FullName;
				}
				sb.Append("new ").Append(elementTypeName).Append("[").Append(((Array)arg.Value).Length).Append("] { ");
				string sep = "";
				foreach (CustomAttributeTypedArgument elem in (CustomAttributeTypedArgument[])arg.Value)
				{
					sb.Append(sep);
					sep = ", ";
					AppendValue(sb, elementType, elem);
				}
				sb.Append(" }");
			}
			else
			{
				if (arg.ArgumentType != type || (type.IsEnum && !arg.Value.Equals(0)))
				{
					sb.Append('(');
					sb.Append(arg.ArgumentType.FullName);
					sb.Append(')');
				}
				sb.Append(arg.Value);
			}
		}
Пример #11
0
		private static CustomAttributeTypedArgument ReadFixedArg(Assembly asm, ByteReader br, Type type)
		{
			Universe u = asm.universe;
			if (type == u.System_String)
			{
				return new CustomAttributeTypedArgument(type, br.ReadString());
			}
			else if (type == u.System_Type)
			{
				return new CustomAttributeTypedArgument(type, ReadType(asm, br));
			}
			else if (type == u.System_Object)
			{
				return ReadFixedArg(asm, br, ReadFieldOrPropType(asm, br));
			}
			else if (type.IsArray)
			{
				int length = br.ReadInt32();
				if (length == -1)
				{
					return new CustomAttributeTypedArgument(type, null);
				}
				Type elementType = type.GetElementType();
				CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
				for (int i = 0; i < length; i++)
				{
					array[i] = ReadFixedArg(asm, br, elementType);
				}
				return new CustomAttributeTypedArgument(type, array);
			}
			else if (type.IsEnum)
			{
				return new CustomAttributeTypedArgument(type, ReadFixedArg(asm, br, type.GetEnumUnderlyingTypeImpl()).Value);
			}
			else
			{
				switch (Type.GetTypeCode(type))
				{
					case TypeCode.Boolean:
						return new CustomAttributeTypedArgument(type, br.ReadByte() != 0);
					case TypeCode.Char:
						return new CustomAttributeTypedArgument(type, br.ReadChar());
					case TypeCode.Single:
						return new CustomAttributeTypedArgument(type, br.ReadSingle());
					case TypeCode.Double:
						return new CustomAttributeTypedArgument(type, br.ReadDouble());
					case TypeCode.SByte:
						return new CustomAttributeTypedArgument(type, br.ReadSByte());
					case TypeCode.Int16:
						return new CustomAttributeTypedArgument(type, br.ReadInt16());
					case TypeCode.Int32:
						return new CustomAttributeTypedArgument(type, br.ReadInt32());
					case TypeCode.Int64:
						return new CustomAttributeTypedArgument(type, br.ReadInt64());
					case TypeCode.Byte:
						return new CustomAttributeTypedArgument(type, br.ReadByte());
					case TypeCode.UInt16:
						return new CustomAttributeTypedArgument(type, br.ReadUInt16());
					case TypeCode.UInt32:
						return new CustomAttributeTypedArgument(type, br.ReadUInt32());
					case TypeCode.UInt64:
						return new CustomAttributeTypedArgument(type, br.ReadUInt64());
					default:
						throw new InvalidOperationException();
				}
			}
		}
Пример #12
0
		private static void AppendValue(StringBuilder sb, CustomAttributeTypedArgument arg)
		{
			if (arg.ArgumentType == arg.ArgumentType.Module.universe.System_String)
			{
				sb.Append('"').Append(arg.Value).Append('"');
			}
			else
			{
				if (arg.ArgumentType.IsEnum)
				{
					sb.Append('(');
					sb.Append(arg.ArgumentType.FullName);
					sb.Append(')');
				}
				sb.Append(arg.Value);
			}
		}