public void TestMergeCollections() { TestAttributeForCollT1 a1 = new TestAttributeForCollT1(1); TestAttributeForCollT2 a2 = new TestAttributeForCollT2(2); TestAttributeForCollT3 a3 = new TestAttributeForCollT3(3); TestAttributeForCollT4 a4 = new TestAttributeForCollT4(4); TestAttributeForCollT5 a5 = new TestAttributeForCollT5(5); AttributeExtCollection testColl1 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2 }); AttributeExtCollection testColl2 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a3, a4, a5 }); AttributeExtCollection merged1 = testColl1.MergeAttributeCollections(testColl2); Assert.AreEqual(a3, merged1.GetAttributeAt(0), "wrong merged"); Assert.AreEqual(a4, merged1.GetAttributeAt(1), "wrong merged"); Assert.AreEqual(a5, merged1.GetAttributeAt(2), "wrong merged"); Assert.AreEqual(a1, merged1.GetAttributeAt(3), "wrong merged"); Assert.AreEqual(a2, merged1.GetAttributeAt(4), "wrong merged"); Assert.AreEqual(5, merged1.Count, "result length"); AttributeExtCollection merged2 = testColl2.MergeAttributeCollections(testColl1); Assert.AreEqual(a1, merged2.GetAttributeAt(0), "wrong merged"); Assert.AreEqual(a2, merged2.GetAttributeAt(1), "wrong merged"); Assert.AreEqual(a3, merged2.GetAttributeAt(2), "wrong merged"); Assert.AreEqual(a4, merged2.GetAttributeAt(3), "wrong merged"); Assert.AreEqual(a5, merged2.GetAttributeAt(4), "wrong merged"); Assert.AreEqual(5, merged2.Count, "result length"); }
/// <summary> /// check if CLS type is a fusioned form; /// </summary> private void CheckForFusionedForm() { // initalize for non-splittable: m_separatedClsType = m_clsType; m_separatedAttrsBuilder = m_compactTypeAttrsBuilder; // check for splittable if (m_clsType.IsSubclassOf(ReflectionHelper.BoxedValueBaseType)) { AttributeExtCollection attrColl = AttributeExtCollection. ConvertToAttributeCollection(m_clsType.GetCustomAttributes(true)); if (!(attrColl.IsInCollection(typeof(RepositoryIDAttribute)))) { // invalid boxed value type throw new INTERNAL(890, CompletionStatus.Completed_MayBe); } String boxedValueRepId = ((RepositoryIDAttribute)attrColl.GetAttributeForType(typeof(RepositoryIDAttribute))).Id; try { SplitBoxedForm(boxedValueRepId); } catch (Exception e) { // invalid boxedValueType found: static method missing or not callable: BoxedValueBase.GET_FIRST_NONBOXED_TYPE_METHODNAME Trace.WriteLine("problematic boxed val found: " + m_clsType.FullName + "; ex: " + e); throw new INTERNAL(890, CompletionStatus.Completed_MayBe); } } }
protected void SetSeparated(Type separatedType, CustomAttributeBuilder[] separatedAttrs, object[] separatedAttrInstances) { lock (this) { m_separatedClsType = separatedType; m_separatedAttrsBuilder = separatedAttrs; m_separatedAttrInstances = AttributeExtCollection.ConvertToAttributeCollection(separatedAttrInstances); } }
private object MapToIdlBoxedValueType(Type clsType, bool boxInAny) { // dotNetType is subclass of BoxedValueBase if (!clsType.IsSubclassOf(ReflectionHelper.BoxedValueBaseType)) { // mapper error: MapToIdlBoxedValue found incorrect type throw new INTERNAL(1929, CompletionStatus.Completed_MayBe); } Type boxedType; object[] attributesOnBoxed = new object[0]; try { boxedType = (Type)clsType.InvokeMember(BoxedValueBase.GET_BOXED_TYPE_METHOD_NAME, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly, null, null, new object[0]); attributesOnBoxed = (object[])clsType.InvokeMember(BoxedValueBase.GET_BOXED_TYPE_ATTRIBUTES_METHOD_NAME, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly, null, null, new object[0]); } catch (Exception) { // invalid type: clsType // static method missing or not callable: // BoxedValueBase.GET_BOXED_TYPE_METHOD_NAME throw new INTERNAL(1930, CompletionStatus.Completed_MayBe); } if (boxInAny) { omg.org.CORBA.TypeCode boxed = CreateOrGetTypeCodeForType(boxedType, AttributeExtCollection.ConvertToAttributeCollection(attributesOnBoxed)); ValueBoxTC result = new ValueBoxTC(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), boxed); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); return(result); } else { // don't use boxed form // therefore create a typecode for the type boxed inside // e.g. in case of a boxed sequence of int, there will be a idlsequence typecode with int as element type created. // e.g. in case, where a sequence of boxed valuetype is boxed, an idl sequence will be created containing a typecode // for the boxed type. omg.org.CORBA.TypeCodeImpl forBoxed = CreateOrGetTypeCodeForType(boxedType, AttributeExtCollection.ConvertToAttributeCollection(attributesOnBoxed)); return(forBoxed); } }
private void DetermineContentDependenciesFromFields() { FieldInfo[] fields = ReflectionHelper.GetAllDeclaredInstanceFieldsOrdered(m_forType); foreach (FieldInfo info in fields) { if (!m_manager.IsDefaultMapped(info.FieldType) && !info.FieldType.Equals(m_forType)) { // only add to dependencies, if not default mapped AddToDepList(m_dependenciesContent, CreateMapTypeInfo(info.FieldType, AttributeExtCollection.ConvertToAttributeCollection(info.GetCustomAttributes(true))), true); } } }
private void DetermineContentDependenciesFromProperties() { BindingFlags flags = BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public; PropertyInfo[] properties = m_forType.GetProperties(flags); foreach (PropertyInfo info in properties) { if (!m_manager.IsDefaultMapped(info.PropertyType) && !info.PropertyType.Equals(m_forType)) { // only add to dependencies, if not default mapped AddToDepList(m_dependenciesContent, CreateMapTypeInfo(info.PropertyType, AttributeExtCollection.ConvertToAttributeCollection(info.GetCustomAttributes(true))), false); } } }
/// <summary>creates a ParameterSpec for a ParameterInfo</summary> public ParameterSpec(ParameterInfo forParamInfo) { if (forParamInfo.IsOut) { m_direction = ParameterDirection.s_out; } else if (forParamInfo.ParameterType.IsByRef) { m_direction = ParameterDirection.s_inout; } else { m_direction = ParameterDirection.s_in; } m_paramName = forParamInfo.Name; // custom attributes System.Object[] attrs = forParamInfo.GetCustomAttributes(false); m_paramType = new TypeContainer(forParamInfo.ParameterType, AttributeExtCollection. ConvertToAttributeCollection(attrs), true); }
public void TestRemoveElement() { TestAttributeForCollT1 a1 = new TestAttributeForCollT1(1); TestAttributeForCollT2 a2 = new TestAttributeForCollT2(2); TestAttributeForCollT3 a3 = new TestAttributeForCollT3(3); TestAttributeForCollT4 a4 = new TestAttributeForCollT4(4); TestAttributeForCollT5 a5 = new TestAttributeForCollT5(5); Attribute removed; AttributeExtCollection testColl1 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2, a3, a4, a5 }); AttributeExtCollection result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT2), out removed); Assert.AreEqual(a2, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT3), out removed); Assert.AreEqual(a3, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT4), out removed); Assert.AreEqual(a4, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a5, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); result1 = testColl1.RemoveAttributeOfType(typeof(TestAttributeForCollT5), out removed); Assert.AreEqual(a5, removed, "wrong removed"); Assert.AreEqual(a1, result1.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(a2, result1.GetAttributeAt(1), "wrong removed"); Assert.AreEqual(a3, result1.GetAttributeAt(2), "wrong removed"); Assert.AreEqual(a4, result1.GetAttributeAt(3), "wrong removed"); Assert.AreEqual(4, result1.Count, "result length"); // start with one elem coll AttributeExtCollection testColl2 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1 }); AttributeExtCollection result2 = testColl2.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(0, result2.Count, "result length"); // start with two elem coll AttributeExtCollection testColl3 = AttributeExtCollection.ConvertToAttributeCollection(new object[] { a1, a2 }); AttributeExtCollection result3 = testColl3.RemoveAttributeOfType(typeof(TestAttributeForCollT1), out removed); Assert.AreEqual(a1, removed, "wrong removed"); Assert.AreEqual(a2, result3.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(1, result3.Count, "result length"); result3 = testColl3.RemoveAttributeOfType(typeof(TestAttributeForCollT2), out removed); Assert.AreEqual(a2, removed, "wrong removed"); Assert.AreEqual(a1, result3.GetAttributeAt(0), "wrong removed"); Assert.AreEqual(1, result3.Count, "result length"); }