static bool AreSame (ArrayType a, ArrayType b) { if (a.Rank != b.Rank) return false; // TODO: dimensions return true; }
TypeReference ImportTypeSpecification (TypeReference type, ImportGenericContext context) { switch (type.etype) { case ElementType.SzArray: var vector = (ArrayType) type; return new ArrayType (ImportType (vector.ElementType, context)); case ElementType.Ptr: var pointer = (PointerType) type; return new PointerType (ImportType (pointer.ElementType, context)); case ElementType.ByRef: var byref = (ByReferenceType) type; return new ByReferenceType (ImportType (byref.ElementType, context)); case ElementType.Pinned: var pinned = (PinnedType) type; return new PinnedType (ImportType (pinned.ElementType, context)); case ElementType.Sentinel: var sentinel = (SentinelType) type; return new SentinelType (ImportType (sentinel.ElementType, context)); case ElementType.CModOpt: var modopt = (OptionalModifierType) type; return new OptionalModifierType ( ImportType (modopt.ModifierType, context), ImportType (modopt.ElementType, context)); case ElementType.CModReqD: var modreq = (RequiredModifierType) type; return new RequiredModifierType ( ImportType (modreq.ModifierType, context), ImportType (modreq.ElementType, context)); case ElementType.Array: var array = (ArrayType) type; var imported_array = new ArrayType (ImportType (array.ElementType, context)); if (array.IsVector) return imported_array; var dimensions = array.Dimensions; var imported_dimensions = imported_array.Dimensions; imported_dimensions.Clear (); for (int i = 0; i < dimensions.Count; i++) { var dimension = dimensions [i]; imported_dimensions.Add (new ArrayDimension (dimension.LowerBound, dimension.UpperBound)); } return imported_array; case ElementType.GenericInst: var instance = (GenericInstanceType) type; var element_type = ImportType (instance.ElementType, context); var imported_instance = new GenericInstanceType (element_type); var arguments = instance.GenericArguments; var imported_arguments = imported_instance.GenericArguments; for (int i = 0; i < arguments.Count; i++) imported_arguments.Add (ImportType (arguments [i], context)); return imported_instance; case ElementType.Var: var var_parameter = (GenericParameter) type; return context.TypeParameter (type.DeclaringType.FullName, var_parameter.Position); case ElementType.MVar: var mvar_parameter = (GenericParameter) type; return context.MethodParameter (mvar_parameter.DeclaringMethod.Name, mvar_parameter.Position); } throw new NotSupportedException (type.etype.ToString ()); }
TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context) { switch (type.etype) { case ElementType.SzArray: var vector = (ArrayType)type; return(new ArrayType(ImportType(vector.ElementType, context))); case ElementType.Ptr: var pointer = (PointerType)type; return(new PointerType(ImportType(pointer.ElementType, context))); case ElementType.ByRef: var byref = (ByReferenceType)type; return(new ByReferenceType(ImportType(byref.ElementType, context))); case ElementType.Pinned: var pinned = (PinnedType)type; return(new PinnedType(ImportType(pinned.ElementType, context))); case ElementType.Sentinel: var sentinel = (SentinelType)type; return(new SentinelType(ImportType(sentinel.ElementType, context))); case ElementType.CModOpt: var modopt = (OptionalModifierType)type; return(new OptionalModifierType( ImportType(modopt.ModifierType, context), ImportType(modopt.ElementType, context))); case ElementType.CModReqD: var modreq = (RequiredModifierType)type; return(new RequiredModifierType( ImportType(modreq.ModifierType, context), ImportType(modreq.ElementType, context))); case ElementType.Array: var array = (ArrayType)type; var imported_array = new ArrayType(ImportType(array.ElementType, context)); if (array.IsVector) { return(imported_array); } var dimensions = array.Dimensions; var imported_dimensions = imported_array.Dimensions; imported_dimensions.Clear(); for (int i = 0; i < dimensions.Count; i++) { var dimension = dimensions [i]; imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound)); } return(imported_array); case ElementType.GenericInst: var instance = (GenericInstanceType)type; var element_type = ImportType(instance.ElementType, context); var imported_instance = new GenericInstanceType(element_type); var arguments = instance.GenericArguments; var imported_arguments = imported_instance.GenericArguments; for (int i = 0; i < arguments.Count; i++) { imported_arguments.Add(ImportType(arguments [i], context)); } return(imported_instance); case ElementType.Var: var var_parameter = (GenericParameter)type; return(context.TypeParameter(type.DeclaringType.FullName, var_parameter.Position)); case ElementType.MVar: var mvar_parameter = (GenericParameter)type; return(context.MethodParameter(mvar_parameter.DeclaringMethod.Name, mvar_parameter.Position)); } throw new NotSupportedException(type.etype.ToString()); }