private void Marshal(Type type, AttributeExtCollection attributes, object val, CdrOutputStream cdrOut) { Serializer ser = m_serFactory.Create(type, attributes); ser.Serialize(val, cdrOut); }
private object Unmarshal(Type type, AttributeExtCollection attributes, CdrInputStream cdrIn) { Serializer ser = m_serFactory.Create(type, attributes); return(ser.Deserialize(cdrIn)); }
internal DependencyInformation(Type forType, AttributeExtCollection attributesAfterMap, DependencyManager manager) { m_forType = forType; m_manager = manager; DetermineInheritanceDependencies(); DetermineContentDependencies(attributesAfterMap); }
public object MapToIdlSequence(Type clsType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // sequence should not contain itself! -> do not register typecode omg.org.CORBA.TypeCode elementTC = CreateOrGetTypeCodeForType(clsType.GetElementType(), elemTypeAttributes); return(new SequenceTC(elementTC, bound)); }
public object read_boxed(BoxedValueAttribute attr, Type boxedType, AttributeExtCollection boxedTypeAttrs) { if (boxedTypeAttrs == null) { boxedTypeAttrs = AttributeExtCollection.EmptyCollection; } boxedTypeAttrs = boxedTypeAttrs.MergeAttribute(attr); return(Unmarshal(boxedType, boxedTypeAttrs, m_cdrIn)); }
/// <summary> /// used for recursive type code creation /// </summary> private void RegisterCreatedTypeCodeForType(Type forType, AttributeExtCollection attributes, TypeCodeImpl typeCode) { TypecodeForTypeKey key = new TypecodeForTypeKey(forType, attributes); lock (m_alreadyCreatedTypeCodes) m_alreadyCreatedTypeCodes[key] = typeCode; }
public TypecodeForTypeKey(Type forType, AttributeExtCollection attrs) { if ((forType == null) || (attrs == null)) { throw new INTERNAL(801, CompletionStatus.Completed_MayBe); } m_type = forType; m_attributes = attrs; }
public object MapToIdlSequence(System.Type clsType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { Type serializerType = typeof(IdlSequenceSerializer <>).MakeGenericType(clsType.GetElementType()); ConstructorInfo ci = serializerType.GetConstructor(new Type[] { AttributeExtCollection.ClassType, ReflectionHelper.Int32Type, ReflectionHelper.BooleanType, SerializerFactory.ClassType }); return(ci.Invoke(new object[] { elemTypeAttributes, bound, m_config.SequenceSerializationAllowNull, this })); }
protected void SetSeparated(Type separatedType, CustomAttributeBuilder[] separatedAttrs, object[] separatedAttrInstances) { lock (this) { m_separatedClsType = separatedType; m_separatedAttrsBuilder = separatedAttrs; m_separatedAttrInstances = AttributeExtCollection.ConvertToAttributeCollection(separatedAttrInstances); } }
public MapTypeInfo(Type type, Util.AttributeExtCollection attributes, bool isFwdDeclPossible) { if ((type == null) || (attributes == null)) { throw new ArgumentException("type and attributes must be != null"); } m_type = type; m_attributes = attributes; m_isFwdDeclPossible = isFwdDeclPossible; }
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); } }
public void TestCollectionEqualsNotEqual() { TestAttributeForCollT1 a1 = new TestAttributeForCollT1(1); TestAttributeForCollT2 a2 = new TestAttributeForCollT2(2); TestAttributeForCollT3 a3 = new TestAttributeForCollT3(3); AttributeExtCollection c1 = new AttributeExtCollection(new Attribute[] { a1, a2, a3 }); AttributeExtCollection c2 = new AttributeExtCollection(new Attribute[] { a3, a2 }); Assert.IsTrue(!c1.Equals(c2), "collection equality"); }
/// <summary> /// returns true, if a forward declaration for the given type info is possible; /// it's not possible e.g. for Boxed value types. /// </summary> public bool IsForwardDeclPossible(Type forType, AttributeExtCollection attributes) { // boxed value types can't have forward declaration --> be sure to not include boxed value types here // CORBA 2.3: only concrete/abstract value types and concrete/abstract/local interface can be fwd declared. return((ClsToIdlMapper.IsMappedToConcreteValueType(forType) || ClsToIdlMapper.IsMappedToAbstractValueType(forType, attributes) || ClsToIdlMapper.IsMappedToConcreteInterface(forType) || ClsToIdlMapper.IsMappedToAbstractInterface(forType) || ClsToIdlMapper.IsMappedToLocalInterface(forType)) && (!IsMappedBeforeGeneration(forType))); // don't create fwd references for entities, which are mapped before generation run }
/// <summary> /// return the short type name of typedef for the idl sequence /// </summary> public static string GetTypeDefAliasForSequenceType(Type seqType, int bound, AttributeExtCollection elemTypeAttributes, out string namespaceName, out string elemTypeFullQualName) { elemTypeFullQualName = (string)ClsToIdlMapper.GetSingleton().MapClsType(seqType.GetElementType(), elemTypeAttributes, s_genIdlNameforClsTypeNoAnonSeq); string elemTypeNameId = elemTypeFullQualName.Replace(":", "_"); elemTypeNameId = elemTypeNameId.Replace(" ", "_"); string typedefName = "seqTd" + bound + "_" + elemTypeNameId; namespaceName = "org.omg.seqTypeDef"; return(typedefName); }
public object MapToIdlSequence(System.Type dotNetType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { if (m_useAnonymousSequences) { string refToElemType = (string)m_mapper.MapClsType(dotNetType.GetElementType(), elemTypeAttributes, this); return("sequence<" + refToElemType + ">"); } else { // use a typedef for non-anonymous sequence return(IdlNaming.GetFullyQualifiedIdlTypeDefAliasForSequenceType(dotNetType, bound, elemTypeAttributes)); } }
public static long DetermineArrayAttributeOrderNr(AttributeExtCollection elemTypeAttributes) { Attribute idlorderAttr = elemTypeAttributes.GetHighestOrderAttribute(); if (idlorderAttr != null) { return(((IOrderedAttribute)idlorderAttr).OrderNr + 1); } else { return(0); } }
public object decode_value([IdlSequence(0L)] byte[] data, omg.org.CORBA.TypeCode tc) { CdrEncapsulationInputStream inputStream = new CdrEncapsulationInputStream(data, m_version); Type marshalAs = ((TypeCodeImpl)tc).GetClsForTypeCode(); AttributeExtCollection marshalAsAttrs = ((TypeCodeImpl)tc).GetClsAttributesForTypeCode(); Serializer ser = m_serFactory.Create(marshalAs, marshalAsAttrs); return(ser.Deserialize(inputStream)); }
private string[] DetermineContextElements(MethodInfo method) { AttributeExtCollection methodAttrs = ReflectionHelper.GetCustomAttriutesForMethod(method, true, ReflectionHelper.ContextElementAttributeType); string[] result = new string[methodAttrs.Count]; for (int i = 0; i < methodAttrs.Count; i++) { result[i] = ((ContextElementAttribute)methodAttrs[i]).ContextElementKey; } return(result); }
private void DetermineContentDependenciesFromElementType(AttributeExtCollection attributesAfterMap) { Type elemType = m_forType.GetElementType(); if (elemType != null) { if (!m_manager.IsDefaultMapped(elemType) && !elemType.Equals(m_forType)) { AddToDepList(m_dependenciesContent, CreateMapTypeInfo(elemType, attributesAfterMap), false); // for sequence of sequence, don't use anonymous seq for element type } } // else: should not happen }
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); } } }
/// <summary>used by type code creating methods</summary> internal static TypeCodeImpl CreateTypeCodeForTypeInternal(Type forType, AttributeExtCollection attributes, TypeCodeCreater typeCodeCreator) { if (forType != null) { ClsToIdlMapper mapper = ClsToIdlMapper.GetSingleton(); return((TypeCodeImpl)mapper.MapClsType(forType, attributes, typeCodeCreator)); } else { // if no type info present, map to null typecode; the case can't be handled by cls to idl mapper return(new NullTC()); } }
public object MapToIdlArray(Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // array should not contain itself! -> do not register typecode // get the typecode for the array element type omg.org.CORBA.TypeCode elementTC = CreateOrGetTypeCodeForType(clsType.GetElementType(), elemTypeAttributes); // for multidim arrays, nest array tcs ArrayTC arrayTC = new ArrayTC(elementTC, dimensions[dimensions.Length - 1]); // the innermost array tc for the rightmost dimension for (int i = dimensions.Length - 2; i >= 0; i--) { arrayTC = new ArrayTC(arrayTC, dimensions[i]); } return(arrayTC); }
private TypeCodeImpl CreateOrGetTypeCodeForType(Type forType, AttributeExtCollection attributes) { TypecodeForTypeKey key = new TypecodeForTypeKey(forType, attributes); TypeCodeImpl result; lock (m_alreadyCreatedTypeCodes) result = m_alreadyCreatedTypeCodes[key] as TypeCodeImpl; if (result == null) { result = Repository.CreateTypeCodeForTypeInternal(forType, attributes, this); } return(result); }
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>gets the request method name for attribute, if possible.</summary> private static string GetRequestMethodNameFromAttr(MethodInfo info) { AttributeExtCollection methodAttributes = ReflectionHelper.GetCustomAttriutesForMethod(info, true); if (methodAttributes.IsInCollection(ReflectionHelper.FromIdlNameAttributeType)) { FromIdlNameAttribute idlNameAttr = (FromIdlNameAttribute)methodAttributes.GetAttributeForType(ReflectionHelper.FromIdlNameAttributeType); return(idlNameAttr.IdlName); } else { return(null); } }
/// <summary> /// takes the type and the attributes either in compact or separated form (use alreadySeparated to specify). /// </summary> /// <param name="clsType">the type in this container</param> /// <param name="attrs">the cls type attributes</param> /// <param name="assignableFromType">can be used to specify the type of values assignable to clsType; /// useful e.g for uints, which are casted to ints</param> /// <param name="alreadySeparated">is clsType in separated form or not</param> public TypeContainer(Type clsType, AttributeExtCollection attrs, Type assignableFromType, bool alreadySeparated) { if (attrs == null) { throw new ArgumentException("TypeContainer; attrs must be != null"); } ArrayList custAttrBuilders = new ArrayList(); foreach (Object attr in attrs) { if (attr is IIdlAttribute) { CustomAttributeBuilder builder = ((IIdlAttribute)attr).CreateAttributeBuilder(); custAttrBuilders.Add(builder); } else { throw new INTERNAL(454, CompletionStatus.Completed_MayBe); } } CustomAttributeBuilder[] custAttrBuilderArray = (CustomAttributeBuilder[])custAttrBuilders.ToArray(typeof(CustomAttributeBuilder)); m_clsType = clsType; m_compactTypeAttrsBuilder = custAttrBuilderArray; m_compactTypeAttrInstances = attrs; m_assignableFromType = assignableFromType; if (alreadySeparated) { m_separatedClsType = clsType; m_separatedAttrsBuilder = custAttrBuilderArray; m_separatedAttrInstances = attrs; } else { m_separatedClsType = null; m_separatedAttrsBuilder = null; m_separatedAttrInstances = null; } }
private ArgumentMapping DetermineReturnParamMapping(MethodInfo method, SerializerFactory serFactory) { ArgumentMapping returnMapping; // return value if (!method.ReturnType.Equals(ReflectionHelper.VoidType)) { AttributeExtCollection returnAttrs = ReflectionHelper.CollectReturnParameterAttributes(method); Serializer retMappingSer = serFactory.Create(method.ReturnType, returnAttrs); returnMapping = new ArgumentMapping(retMappingSer, ArgumentsKind.Return); } else { // no retrun value to serialise/deserialise returnMapping = new ArgumentMapping(); } return(returnMapping); }
public void TestMergeAttribute() { 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, a3, a4 }); AttributeExtCollection merged1 = testColl1.MergeAttribute(a5); Assert.AreEqual(a5, merged1.GetAttributeAt(0), "wrong merged"); Assert.AreEqual(a1, merged1.GetAttributeAt(1), "wrong merged"); Assert.AreEqual(a2, merged1.GetAttributeAt(2), "wrong merged"); Assert.AreEqual(a3, merged1.GetAttributeAt(3), "wrong merged"); Assert.AreEqual(a4, merged1.GetAttributeAt(4), "wrong merged"); Assert.AreEqual(5, merged1.Count, "result length"); }
/// <summary>determines the serialiser responsible for a specified formal type and the parameterattributes attributes</summary> /// <param name="formal">The formal type. If formal is modified through mapper, result is returned in this parameter</param> /// <param name="attributes">the parameter/field attributes</param> /// <returns></returns> private Serializer DetermineSerializer(Type formal, AttributeExtCollection attributes) { CustomMappingDesc customMappingUsed; Serializer serialiser = (Serializer)s_mapper.MapClsTypeWithTransform(ref formal, ref attributes, this, out customMappingUsed); // formal can be transformed if (serialiser == null) { // no serializer present for Type: formal Trace.WriteLine("no serialiser for Type: " + formal); throw new BAD_PARAM(9001, CompletionStatus.Completed_MayBe); } Debug.WriteLine("determined to serialize formal type " + formal + " with : " + serialiser); if (customMappingUsed != null) { // wrap serializer to apply custom mapping serialiser = new CustomMappingDecorator(customMappingUsed, serialiser); } return(serialiser); }
private void DetermineContentDependenciesFromExceptions(MethodInfo thrower) { AttributeExtCollection methodAttributes = ReflectionHelper.GetCustomAttriutesForMethod(thrower, true); foreach (Attribute attr in methodAttributes) { if (ReflectionHelper.ThrowsIdlExceptionAttributeType. IsAssignableFrom(attr.GetType())) { Type exceptionType = ((ThrowsIdlExceptionAttribute)attr).ExceptionType; AddToDepList(m_dependenciesContent, CreateMapTypeInfo(exceptionType, AttributeExtCollection.EmptyCollection), false); } } // default exception, which can be thrown AddToDepList(m_dependenciesContent, CreateMapTypeInfo(typeof(GenericUserException), AttributeExtCollection.EmptyCollection), false); }