/// <summary> /// See <see cref="System.Attribute.Equals"/>. /// </summary> public override bool Equals(object obj) { IdlArrayAttribute other = obj as IdlArrayAttribute; if (other == null) { return(false); } return(m_firstDimensionSize == other.m_firstDimensionSize && m_orderNr == other.m_orderNr); }
private AttributeExtCollection GetAttributesForDimension() { AttributeExtCollection attrColl = ((TypeCodeImpl)m_innerDimension).GetClsAttributesForTypeCode(); IdlArrayAttribute potentialOldArrayAttribute = attrColl.GetHighestOrderAttribute() as IdlArrayAttribute; int[] dimensions; long orderNr; if (potentialOldArrayAttribute != null) { dimensions = ExtractCombinedDimensions(ref attrColl, potentialOldArrayAttribute); orderNr = potentialOldArrayAttribute.OrderNr; } else { dimensions = new int[] { m_length }; orderNr = IdlArrayAttribute.DetermineArrayAttributeOrderNr(attrColl); } // now add attributes for dimensions IdlArrayAttribute newAttribute = new IdlArrayAttribute(orderNr, dimensions[0]); attrColl = attrColl.MergeAttribute(newAttribute); for (int i = 1; i < dimensions.Length; i++) { attrColl = attrColl.MergeAttribute(new IdlArrayDimensionAttribute(orderNr, i, dimensions[i])); } return attrColl; }
private int[] ExtractCombinedDimensions(ref AttributeExtCollection attrColl, IdlArrayAttribute innerAttribute) { attrColl = attrColl.RemoveAttribute(innerAttribute); IList dimensionAttributes; attrColl = attrColl.RemoveAssociatedAttributes(innerAttribute.OrderNr, out dimensionAttributes); int[] dimensions = new int[2 + dimensionAttributes.Count]; // 1 for this dimension, 1 for the old first dimension + those for the dimensionAttributes dimensions[0] = m_length; dimensions[1] = innerAttribute.FirstDimensionSize; for (int i = 0; i < dimensionAttributes.Count; i++) { dimensions[((IdlArrayDimensionAttribute)dimensionAttributes[i]).DimensionNr + 1] = ((IdlArrayDimensionAttribute)dimensionAttributes[i]).DimensionSize; // shift rigth } return dimensions; }
private TypeContainer GetTypeContainerForMultiDimArray(TypeContainer elemType, int[] dimensions) { string clsArrayRep = "["; for (int i = 1; i < dimensions.Length; i++) { clsArrayRep = clsArrayRep + ","; } clsArrayRep = clsArrayRep + "]"; // create CLS array type with the help of GetType(), otherwise not possible Type arrayType; // because not fully defined types are possible, use module and not assembly to get type from Module declModule = elemType.GetCompactClsType().Module; arrayType = declModule.GetType(elemType.GetCompactClsType().FullName + clsArrayRep); // not nice, better solution ? Debug.WriteLine("created array type: " + arrayType); // determine the needed attributes: IdlArray is required by the array itself (+optional dimension attrs); // combine with the attribute from the element type // possible are: IdlArray (for array of array), IdlSequence (for array of sequence), ObjectIdlType, // WideChar, StringValue // invariant: boxed value attribute is not among them, because elem type // is in the compact form AttributeExtCollection elemAttributes = elemType.GetCompactTypeAttrInstances(); long arrayAttrOrderNr = IdlArrayAttribute.DetermineArrayAttributeOrderNr(elemAttributes); IdlArrayAttribute arrayAttr = new IdlArrayAttribute(arrayAttrOrderNr, dimensions[0]); // at least one dimension available, because of grammar AttributeExtCollection arrayAttributes = new AttributeExtCollection(elemAttributes); arrayAttributes = arrayAttributes.MergeAttribute(arrayAttr); for (int i = 1; i < dimensions.Length; i++) { IdlArrayDimensionAttribute dimAttr = new IdlArrayDimensionAttribute(arrayAttrOrderNr, i, dimensions[i]); arrayAttributes = arrayAttributes.MergeAttribute(dimAttr); } return new TypeContainer(arrayType, arrayAttributes); }
private int[] DetermineIdlArrayDimensions(Type clsType, IdlArrayAttribute arrayAttr, ref AttributeExtCollection modifiedAttributes) { // get all the array dimensions, first is inside the IDLArrayAttribute; others are separate int[] dimensions = new int[clsType.GetArrayRank()]; if (dimensions.Length < 1) { throw new INTERNAL(5643, CompletionStatus.Completed_MayBe); // should never occur } dimensions[0] = arrayAttr.FirstDimensionSize; if (dimensions.Length > 1) { IList dimensionAttrs; modifiedAttributes = modifiedAttributes.RemoveAssociatedAttributes(arrayAttr.OrderNr, out dimensionAttrs); if (dimensionAttrs.Count != dimensions.Length - 1) { throw new INTERNAL(5644, CompletionStatus.Completed_MayBe); // should never occur } for (int i = 0; i < dimensionAttrs.Count; i++) { IdlArrayDimensionAttribute arrayDim = ((IdlArrayDimensionAttribute)dimensionAttrs[i]); dimensions[arrayDim.DimensionNr] = arrayDim.DimensionSize; } } return dimensions; }