Inheritance: Operand
Exemple #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="FieldOperand"/> class.
		/// </summary>
		/// <param name="field">The field.</param>
		/// <param name="instance">The instance.</param>
		public FieldOperand (Field field, Operand instance)
		{
			this.field = field;
			this.instance = instance;
		}
Exemple #2
0
		public FieldOperand (Field field)
		{
			this.field = field;
		}
Exemple #3
0
		/// <summary>
		/// Setups this instance.
		/// </summary>
		public void Setup (int step)
		{
			if (setupStep >= step)
				return;

			setupStep = step;

			if (this.classDefinition is TypeDefinition) {
				TypeDefinition typeDefinition = this.classDefinition as TypeDefinition;

				if (step == 0) {
					if (typeDefinition.GenericParameters != null
							&& typeDefinition.GenericParameters.Count > 0
							&& this.genericInstanceType == null)
						this.isGenericType = true;

					this.hasExplicitLayout = (typeDefinition.Attributes & TypeAttributes.ExplicitLayout) != 0;

					if (typeDefinition.IsEnum) {
						this.isEnum = true;

						foreach (FieldDefinition field in typeDefinition.Fields) {
							if ((field.Attributes & FieldAttributes.RTSpecialName) != 0) {
								this.internalType = this.engine.GetInternalType (field.FieldType.FullName);
								break;
							}
						}

					} else if (typeDefinition.IsValueType) {
						this.isValueType = true;

						this.internalType = this.engine.GetInternalType (this.TypeFullName);

						if (this.internalType == InternalType.NotSet)
							this.internalType = Operands.InternalType.ValueType;

					} else if (typeDefinition.IsClass) {
						this.isClass = true;

						this.internalType = Operands.InternalType.O;

					} else if (typeDefinition.IsInterface) {
						this.isInterface = true;

						this.internalType = Operands.InternalType.O;
					}

					if (this.TypeFullName != Mono.Cecil.Constants.Object 
							&& !this.isInterface
							&& !this.isGenericType) {

						GenericInstanceType genericBaseType = typeDefinition.BaseType as GenericInstanceType;

						if (this.genericInstanceType != null
								&& genericBaseType != null
								&& genericBaseType.GenericArguments [0] is GenericParameter) {
							GenericInstanceType _genericInstanceType = new GenericInstanceType (genericBaseType.ElementType);

							for (int i = 0; i < genericBaseType.GenericArguments.Count; i++)
								_genericInstanceType.GenericArguments.Add (this.genericInstanceType.GenericArguments [i]);

							this._base = this.GetClass (_genericInstanceType);
						} else
							this._base = this.GetClass (typeDefinition.BaseType);
					}

					// initialize base class before marking virtual methods
					if (this._base != null)
						this._base.Setup (step);

					// initialize base interfaces before marking interface methods
					foreach (TypeReference interfaceRef in (this.ClassDefinition as TypeDefinition).Interfaces) {
						this.GetClass(interfaceRef).Setup (step);
					}

					if (this.IsInterface)
						this.AssignInterfaceMethodNumbers();
					else {
						this.MarkInterfaceMethods ();
						if (this._base != null && this._base.ImplementsInterfaces)
							this.MergeBaseInterfaceMethods ();
					}

					this.AddVirtualMethods (this.virtualMethods);

				} else if (step == 1) {
					if (!this.IsGenericType && (!this.isInternal || (this.isInternal && !this.engine.Assembly.IgnoreTypeContent (this.TypeFullName)))) {
						foreach (FieldDefinition field in typeDefinition.Fields) {
							Class _class = this.GetClass (field.FieldType);
							InternalType _internalType = this.engine.GetInternalType (_class.TypeFullName);

							Field _field = new Field (field, _class, this, _internalType);

							fields.Add (_field);
							fieldsDictionary [field.Name] = _field;
						}
					}
				} else
					throw new NotImplementedEngineException ("Getting size of " + this);

			} else if (this.classDefinition is TypeSpecification) {
				if (step == 0) {
					this.isSpecialType = true;
					this.internalType = this.engine.GetInternalType (this.TypeFullName);

					if (this.classDefinition is ArrayType) {
						this._base = this.engine.ArrayClass;
						this.specialTypeElement = this.engine.GetClass ((this.classDefinition as ArrayType).ElementType);

					} else
						this._base = this.engine.GetClass (this.classDefinition.GetOriginalType ());

					// initialize base class
					if (this._base != null)
						this._base.Setup (step);

				} else if (step != 1)
					throw new NotImplementedEngineException ("Can't initialize " + this.TypeFullName + " to step " + step);

			} else
				throw new NotImplementedEngineException (this.TypeFullName + " not supported yet.");
		}