Пример #1
0
			internal FieldEntry(int id, string name, string prefix)
			{
				this.ID = id;
				this.Name = name;
				this.Prefix = prefix;
				this.CodeType = new CodeTypeReference(name);
			}
		public CodeVariableDeclarationStatement(string type,
							 string name, 
							 CodeExpression initExpression)
		{
			this.type = new CodeTypeReference(type);
			this.name = name;
			this.initExpression = initExpression;
		}
Пример #3
0
		public CodeCatchClause(string localName,
					 CodeTypeReference catchExceptionType,
					 params CodeStatement[] statements)
		{
			this.localName = localName;
			this.catchExceptionType = catchExceptionType;
			this.Statements.AddRange(statements);
		}
Пример #4
0
		public CodeCastExpression(CodeTypeReference targetType, CodeExpression expression)
		{
			this.targetType = targetType;
			this.expression = expression;
		}
Пример #5
0
		protected override string DetermineTypeOutput(CodeTypeReference type)
		{
			switch (type.BaseType.ToLower(CultureInfo.InvariantCulture))
			{
				case "system.byte":
					return "ubyte";
				case "system.sbyte":
					return "byte";
				case "system.exception":
					return "Exception";
				case "system.argumentoutofrangeexception":
					return "Exception";
				default:
					return base.DetermineTypeOutput(type);
			}
		}
		public CodeArrayCreateExpression(string createType, 
						  int size)
		{
			this.createType = new CodeTypeReference(createType);
			this.size = size;
		}
Пример #7
0
		public CodeCatchClause(string localName,
					 CodeTypeReference catchExceptionType)
		{
			this.localName = localName;
			this.catchExceptionType = catchExceptionType;
		}
Пример #8
0
		public CodeTypeOfExpression(Type type)
		{
			this.type = new CodeTypeReference(type);
		}
		public CodeArrayCreateExpression(CodeTypeReference createType, 
						  int size)
		{
			this.createType = createType;
			this.size = size;
		}
Пример #10
0
		protected override void OutputType(CodeTypeReference type)
		{
			base.Output.Write(this.GetTypeOutput(type));
		}
Пример #11
0
		public CodeTypeReference(Type baseType)
		{
			if (baseType == null)
			{
				throw new ArgumentNullException("baseType");
			}

			if (baseType.IsGenericParameter)
			{
				this.baseType = baseType.Name;
				this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter;
			}
			else if (baseType.IsGenericTypeDefinition)
				this.baseType = baseType.FullName;
			else if (baseType.IsGenericType)
			{
				this.baseType = baseType.GetGenericTypeDefinition().FullName;
				foreach (Type arg in baseType.GetGenericArguments ())
				{
					if (arg.IsGenericParameter)
						TypeArguments.Add(new CodeTypeReference(new CodeTypeParameter(arg.Name)));
					else
						TypeArguments.Add(new CodeTypeReference(arg));
				}
			}
			else if (baseType.IsArray)
			{
				this.arrayRank = baseType.GetArrayRank();
				this.arrayElementType = new CodeTypeReference(baseType.GetElementType());
				this.baseType = arrayElementType.BaseType;
			}
			else
			{
				Parse(baseType.FullName);
			}
			this.isInterface = baseType.IsInterface;
		}
Пример #12
0
		public CodeMemberField(Type type, string name)
		{
			this.type = new CodeTypeReference(type);
			this.Name = name;
		}
Пример #13
0
		protected override string GetTypeOutput(CodeTypeReference type)
		{
			if ((type.Options & CodeTypeReferenceOptions.GenericTypeParameter) != (CodeTypeReferenceOptions)0)
			{
				return type.BaseType;
			}
			string text;
			if (type.ArrayElementType != null)
			{
				text = this.GetTypeOutput(type.ArrayElementType);
			}
			else
			{
				text = this.DetermineTypeOutput(type);
			}
			int i = type.ArrayRank;
			if (i > 0)
			{
				text += '[';
				for (i--; i > 0; i--)
				{
					text += ',';
				}
				text += ']';
			}
			return text;
		}
Пример #14
0
		public CodeMemberField(CodeTypeReference type, string name)
		{
			this.type = type;
			this.Name = name;
		}
		public CodeTypeReferenceExpression(string type)
		{
			this.type = new CodeTypeReference(type);
		}
Пример #16
0
		public CodeCastExpression(Type targetType, CodeExpression expression)
		{
			this.targetType = new CodeTypeReference(targetType);
			this.expression = expression;
		}
Пример #17
0
		public CodeTypeReference(CodeTypeReference arrayElementType, int arrayRank)
		{
			this.baseType = null;
			this.arrayRank = arrayRank;
			this.arrayElementType = arrayElementType;
		}
Пример #18
0
		protected virtual string DetermineTypeOutput(CodeTypeReference type)
		{
			string baseType = type.BaseType;
			string text = baseType.ToLower(CultureInfo.InvariantCulture);
			string result;
			switch (text)
			{
				case "system.int32":
					result = "int";
					return result;
				case "system.int64":
					result = "long";
					return result;
				case "system.int16":
					result = "short";
					return result;
				case "system.boolean":
					result = "bool";
					return result;
				case "system.char":
					result = "char";
					return result;
				case "system.string":
					result = "string";
					return result;
				case "system.object":
					result = "object";
					return result;
				case "system.void":
					result = "void";
					return result;
				case "system.byte":
					result = "byte";
					return result;
				case "system.sbyte":
					result = "sbyte";
					return result;
				case "system.decimal":
					result = "decimal";
					return result;
				case "system.double":
					result = "double";
					return result;
				case "system.single":
					result = "float";
					return result;
				case "system.uint16":
					result = "ushort";
					return result;
				case "system.uint32":
					result = "uint";
					return result;
				case "system.uint64":
					result = "ulong";
					return result;
			}
			StringBuilder stringBuilder = new StringBuilder(baseType.Length);
			if ((type.Options & CodeTypeReferenceOptions.GlobalReference) != (CodeTypeReferenceOptions)0)
			{
				stringBuilder.Append("global::");
			}
			int num2 = 0;
			for (int i = 0; i < baseType.Length; i++)
			{
				char c = baseType[i];
				if (c != '+' && c != '.')
				{
					if (c == '`')
					{
						stringBuilder.Append(this.CreateEscapedIdentifier(baseType.Substring(num2, i - num2)));
						i++;
						int num3 = i;
						while (num3 < baseType.Length && char.IsDigit(baseType[num3]))
						{
							num3++;
						}
						int count = int.Parse(baseType.Substring(i, num3 - i));
						this.OutputTypeArguments(type.TypeArguments, stringBuilder, count);
						i = num3;
						if (i < baseType.Length && (baseType[i] == '+' || baseType[i] == '.'))
						{
							stringBuilder.Append('.');
							i++;
						}
						num2 = i;
					}
				}
				else
				{
					stringBuilder.Append(this.CreateEscapedIdentifier(baseType.Substring(num2, i - num2)));
					stringBuilder.Append('.');
					i++;
					num2 = i;
				}
			}
			if (num2 < baseType.Length)
			{
				stringBuilder.Append(this.CreateEscapedIdentifier(baseType.Substring(num2)));
			}
			result = stringBuilder.ToString();
			return result;
		}
Пример #19
0
		private void Parse(string baseType)
		{
			if (baseType == null || baseType.Length == 0)
			{
				this.baseType = typeof(void).FullName;
				return;
			}

			int array_start = baseType.IndexOf('[');
			if (array_start == -1)
			{
				this.baseType = baseType;
				return;
			}

			int array_end = baseType.LastIndexOf(']');
			if (array_end < array_start)
			{
				this.baseType = baseType;
				return;
			}

			int lastAngle = baseType.LastIndexOf('>');
			if (lastAngle != -1 && lastAngle > array_end)
			{
				this.baseType = baseType;
				return;
			}
			
			string[] args = baseType.Substring(array_start + 1, array_end - array_start - 1).Split(',');

			if ((array_end - array_start) != args.Length)
			{
				this.baseType = baseType.Substring(0, array_start);
				int escapeCount = 0;
				int scanPos = array_start;
				StringBuilder tb = new StringBuilder();
				while (scanPos < baseType.Length)
				{
					char currentChar = baseType[scanPos];
					
					switch (currentChar)
					{
						case '[':
							if (escapeCount > 1 && tb.Length > 0)
							{
								tb.Append(currentChar);
							}
							escapeCount++;
							break;
						case ']':
							escapeCount--;
							if (escapeCount > 1 && tb.Length > 0)
							{
								tb.Append(currentChar);
							}

							if (tb.Length != 0 && (escapeCount % 2) == 0)
							{
								TypeArguments.Add(tb.ToString());
								tb.Length = 0;
							}
							break;
						case ',':
							if (escapeCount > 1)
							{
								// skip anything after the type name until we 
								// reach the next separator
								while (scanPos + 1 < baseType.Length)
								{
									if (baseType[scanPos + 1] == ']')
									{
										break;
									}
									scanPos++;
								}
							}
							else if (tb.Length > 0)
							{
								CodeTypeReference typeArg = new CodeTypeReference(tb.ToString());
								TypeArguments.Add(typeArg);
								tb.Length = 0;
							}
							break;
						default:
							tb.Append(currentChar);
							break;
					}
					scanPos++;
				}
			}
			else
			{
				arrayElementType = new CodeTypeReference(baseType.Substring(0, array_start));
				arrayRank = args.Length;
			}
		}
		public CodeParameterDeclarationExpression(Type type, string name)
		{
			this.type = new CodeTypeReference(type);
			this.name = name;
		}
Пример #21
0
		public CodeTypeOfExpression(CodeTypeReference type)
		{
			this.type = type;
		}
		//
		// Methods
		//
		public int Add(CodeTypeReference value)
		{
			return List.Add(value);
		}
		public CodeArrayCreateExpression(CodeTypeReference createType, 
						  params CodeExpression[] initializers)
		{
			this.createType = createType;
			this.Initializers.AddRange(initializers);
		}
		public CodeVariableDeclarationStatement(Type type, string name)
		{
			this.type = new CodeTypeReference(type);
			this.name = name;
		}
		public CodeArrayCreateExpression(string createType, 
						  params CodeExpression[] initializers)
		{
			this.createType = new CodeTypeReference(createType);
			this.Initializers.AddRange(initializers);
		}
		public CodeTypeReferenceCollection(CodeTypeReference[] value)
		{
			AddRange(value);
		}
		public CodeArrayCreateExpression(Type createType, 
						  CodeExpression size)
		{
			this.createType = new CodeTypeReference(createType);
			this.sizeExpression = size;
		}
		public CodeDefaultValueExpression(CodeTypeReference type)
		{
			this.type = type;
		}
		public void Remove(CodeTypeReference value)
		{
			List.Remove(value);
		}
		public void AddRange(CodeTypeReference[] value)
		{
			if (value == null)
			{
				throw new ArgumentNullException("value");
			}

			for (int i = 0; i < value.Length; i++)
			{
				Add(value[i]);
			}
		}