/// <summary> /// collects the custom attributes on the return parameter and from /// the return paramters from inherited methods. /// </summary> /// <returns>a collection of attributes</returns> public static AttributeExtCollection CollectReturnParameterAttributes(MethodInfo method) { AttributeExtCollection result = AttributeExtCollection.ConvertToAttributeCollection( method.ReturnTypeCustomAttributes.GetCustomAttributes(true)); if (!method.IsVirtual) { return(result); } MethodInfo baseDecl = method.GetBaseDefinition(); if (!baseDecl.Equals(method)) { // add return param attributes from base definition if not already present result = result.MergeMissingAttributes(baseDecl.ReturnTypeCustomAttributes.GetCustomAttributes(true)); } Type declaringType = method.DeclaringType; // search interfaces for method definition Type[] interfaces = declaringType.GetInterfaces(); foreach (Type interf in interfaces) { MethodInfo found = IsMethodDefinedInInterface(method, interf); if (found != null) { // add return param attributes from interface definition if not already present result = result.MergeMissingAttributes(found.ReturnTypeCustomAttributes.GetCustomAttributes(true)); } } return(result); }
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 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; }
/// <summary> /// returns an attribute collection produced by merging this collection and the argument collection. /// </summary> public AttributeExtCollection MergeAttributeCollections(AttributeExtCollection coll) { object[] resultList = new object[coll.m_attributes.Length + m_attributes.Length]; // first the new ones coll.m_attributes.CopyTo(resultList, 0); // append content of this collection m_attributes.CopyTo(resultList, coll.m_attributes.Length); return(new AttributeExtCollection(resultList)); }
public static AttributeExtCollection GetCustomAttriutesForMethod(MethodInfo member, bool inherit, Type attributeType) { AttributeExtCollection result; object[] attributes; if (attributeType == null) { attributes = member.GetCustomAttributes(inherit); } else { attributes = member.GetCustomAttributes(attributeType, inherit); } result = AttributeExtCollection.ConvertToAttributeCollection(attributes); if (inherit) { // check also for interface methods ... if (member.IsVirtual) { // check also for attributes on interface method, if it's a implementation of an interface method Type declaringType = member.DeclaringType; // search interfaces for method definition Type[] interfaces = declaringType.GetInterfaces(); foreach (Type interf in interfaces) { MethodInfo found = IsMethodDefinedInInterface(member, interf); if (found != null) { // add attributes from interface definition if not already present object[] inheritedAttributes; if (attributeType == null) { inheritedAttributes = found.GetCustomAttributes(inherit); } else { inheritedAttributes = found.GetCustomAttributes(attributeType, inherit); } result = result.MergeMissingAttributes(inheritedAttributes); } } } } return(result); }
/// <summary> /// checks, if thrown is part of the raises attributes (the ThrowsIdlException attributes) of thrower /// </summary> public static bool IsExceptionInRaiseAttributes(Exception thrown, MethodInfo thrower) { AttributeExtCollection methodAttributes = ReflectionHelper.GetCustomAttriutesForMethod(thrower, true); foreach (Attribute attr in methodAttributes) { if (ReflectionHelper.ThrowsIdlExceptionAttributeType. IsAssignableFrom(attr.GetType())) { if (((ThrowsIdlExceptionAttribute)attr).ExceptionType.Equals(thrown.GetType())) { return(true); } } } return(false); }
private AttributeExtCollection RemoveAttributeAtPosition(int position) { object[] newCollection = new object[m_attributes.Length - 1]; // m_attributes.Length must be >= 0, because attr found // copy elements before position to newCollection; don't use Array.Copy, because only few elements for (int i = 0; i < position; i++) { newCollection[i] = m_attributes[i]; } // copy elements after position to newCollection; don't use Array.Copy, because only few elements for (int i = position + 1; i < m_attributes.Length; i++) { newCollection[i - 1] = m_attributes[i]; } AttributeExtCollection result = new AttributeExtCollection(newCollection); if (hashCode != 0) { result.hashCode = hashCode ^ m_attributes[position].GetHashCode(); } return(result); }
/// <summary> /// collects the custom attributes on the current parameter and from /// the paramters from inherited methods. /// </summary> /// <param name="paramInfo">the parameter to check</param> /// <returns>a collection of attributes</returns> public static AttributeExtCollection CollectParameterAttributes(ParameterInfo paramInfo, MethodInfo paramInMethod) { AttributeExtCollection result = AttributeExtCollection.ConvertToAttributeCollection( paramInfo.GetCustomAttributes(true)); if (!paramInMethod.IsVirtual) { return(result); } MethodInfo baseDecl = paramInMethod.GetBaseDefinition(); if (!baseDecl.Equals(paramInMethod)) { // add param attributes from base definition if not already present ParameterInfo[] baseParams = baseDecl.GetParameters(); ParameterInfo baseParamToConsider = baseParams[paramInfo.Position]; result = result.MergeMissingAttributes(baseParamToConsider.GetCustomAttributes(true)); } Type declaringType = paramInMethod.DeclaringType; // search interfaces for method definition Type[] interfaces = declaringType.GetInterfaces(); foreach (Type interf in interfaces) { MethodInfo found = IsMethodDefinedInInterface(paramInMethod, interf); if (found != null) { // add param attributes from interface definition if not already present ParameterInfo[] ifParams = found.GetParameters(); ParameterInfo ifParamToConsider = ifParams[paramInfo.Position]; result = result.MergeMissingAttributes(ifParamToConsider.GetCustomAttributes(true)); } } return(result); }
public static AttributeExtCollection GetCustomAttriutesForField(FieldInfo member, bool inherit) { object[] attributes = member.GetCustomAttributes(inherit); return(AttributeExtCollection.ConvertToAttributeCollection(attributes)); }
public AttributeExtCollection(AttributeExtCollection coll) { hashCode = coll.hashCode; m_attributes = (object[])coll.m_attributes.Clone(); }
public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // use a typedef for arrays, because dimension is part of the name of the thing, the type is an array return IdlNaming.GetFullyQualifiedIdlTypeDefAliasForArrayType(dotNetType, dimensions, elemTypeAttributes); }
private object Unmarshal(Type type, AttributeExtCollection attributes, CdrInputStream cdrIn) { Serializer ser = m_serFactory.Create(type, attributes); return ser.Deserialize(cdrIn); }
public object MapToIdlSequence(Type clsType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // for sequences, the attributes of the element type also influence the mapped type // therefore, use attributes also to check mapped type if (m_depManager.CheckMappedType(clsType, allAttributes)) { return null; // already mapped } string namespaceName; string elemTypeMapped; string typedefName = IdlNaming.GetTypeDefAliasForSequenceType(clsType, bound, elemTypeAttributes, out namespaceName, out elemTypeMapped); string[] modules = IdlNaming.MapNamespaceNameToIdlModules(namespaceName); BeginTypeWithName(clsType, allAttributes, elemTypeAttributes, modules, typedefName); // write type dependant information WriteModuleOpenings(modules); // write typedef if (bound == 0) { m_currentOutputStream.WriteLine("typedef sequence<{0}> {1} ;", elemTypeMapped, typedefName); } else { m_currentOutputStream.WriteLine("typedef sequence<{0}, {1}> {2} ;", elemTypeMapped, bound, typedefName); } m_currentOutputStream.WriteLine(""); EndType(); return null; }
/// <summary> /// return the short type name of typedef for the idl array /// </summary> public static string GetTypeDefAliasForArrayType(Type arrayType, int[] dimensions, AttributeExtCollection elemTypeAttributes, out string namespaceName, out string elemTypeFullQualName) { elemTypeFullQualName = (string)ClsToIdlMapper.GetSingleton().MapClsType(arrayType.GetElementType(), elemTypeAttributes, s_genIdlNameforClsTypeNoAnonSeq); string elemTypeNameId = elemTypeFullQualName.Replace(":", "_"); elemTypeNameId = elemTypeNameId.Replace(" ", "_"); string dimensionRep = ""; for (int i = 0; i < dimensions.Length; i++) { dimensionRep = dimensionRep + "_" + dimensions[i]; } string typedefName = "arrayTd" + dimensionRep + "_" + elemTypeNameId; namespaceName = "org.omg.arrayTypeDef"; return typedefName; }
public object MapToIdlSequence(System.Type dotNetType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elementTypeAttributes) { WriteInclude(dotNetType, allAttributes); return null; }
public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elementTypeAttributes) { WriteInclude(dotNetType, allAttributes); return null; }
private void WriteInclude(Type forType, AttributeExtCollection attributes) { string idlFileName = m_depManager.GetIdlFileForMappedType(forType, attributes); if (idlFileName == null) { throw new Exception("internal error in dep-manager, mapped type missing after mapped before: " + forType); } m_writeTo.WriteLine("#include \"" + idlFileName + "\""); }
/// <summary> /// begin a type definition for the Type dotnetType; This type is mapped to an idl type with name unqualName in the modules modules /// </summary> private void BeginTypeWithName(Type dotNetType, AttributeExtCollection attributes, AttributeExtCollection attributesAfterMap, string[] modules, string unqualName) { // determine the dependencies for the type m_depInfo = m_depManager.GetDependencyInformation(dotNetType, attributesAfterMap); m_openModules = modules; // write it // create output-stream m_toIDLFile = CreateIdlFullName(modules, unqualName); m_currentOutputStream = OpenFile(m_toIDLFile); WriteFileHeader(m_toIDLFile); // register this type as mapped m_depManager.RegisterMappedType(dotNetType, attributes, m_toIDLFile); // map types needed, write fwd references BeforeTypeDefinition(); // protect against redefinition: m_currentOutputStream.Write("#ifndef "); string def = "__"; foreach (string mod in m_openModules) { def = def + mod + "_"; } def = def + unqualName + "__"; m_currentOutputStream.WriteLine(def); m_currentOutputStream.WriteLine("#define " + def); }
public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { throw new NotSupportedException("no fwd declaration possible for this IDL-type"); }
/// <summary> /// Begins the the idl-file for the Type dotNetType: /// Creates the idl-file, writes the generator information header /// </summary> /// <param name="dotNetType"></param> /// <param name="ToIdlFile"></param> private void BeginType(Type dotNetType, AttributeExtCollection attributes, AttributeExtCollection attributesAfterMap, out string[] modules, out string unqualName) { // map the namespace: modules = IdlNaming.MapNamespaceToIdlModules(dotNetType); unqualName = IdlNaming.MapShortTypeNameToIdl(dotNetType); BeginTypeWithName(dotNetType, attributes, attributesAfterMap, modules, unqualName); }
public object MapToIdlArray(Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // for arrays, the attributes of the element type also influence the mapped type // therefore, use attributes also to check mapped type if (m_depManager.CheckMappedType(clsType, allAttributes)) { return null; // already mapped } string namespaceName; string elemTypeMapped; string typedefName = IdlNaming.GetTypeDefAliasForArrayType(clsType, dimensions, elemTypeAttributes, out namespaceName, out elemTypeMapped); string[] modules = IdlNaming.MapNamespaceNameToIdlModules(namespaceName); BeginTypeWithName(clsType, allAttributes, elemTypeAttributes, modules, typedefName); // write type dependant information WriteModuleOpenings(modules); // write typedef string dimensionsRep = String.Empty; for (int i = 0; i < dimensions.Length; i++) { dimensionsRep = dimensionsRep + "[" + dimensions[i] + "]"; } m_currentOutputStream.WriteLine("typedef {0} {1}{2};", elemTypeMapped, typedefName, dimensionsRep); m_currentOutputStream.WriteLine(""); EndType(); return null; }
/// <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; }
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; }
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); } }
/// <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; }
private void Marshal(Type type, AttributeExtCollection attributes, object val, CdrOutputStream cdrOut) { Serializer ser = m_serFactory.Create(type, attributes); ser.Serialize(val, cdrOut); }
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); }
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; }
/// <summary> /// creates a CORBA type code for a CLS type /// </summary> /// <returns>the typecode for the CLS type</returns> internal static TypeCodeImpl CreateTypeCodeForType(Type forType, AttributeExtCollection attributes) { return CreateTypeCodeForTypeInternal(forType, attributes, new TypeCodeCreater()); }
internal override AttributeExtCollection GetClsAttributesForTypeCode() { AttributeExtCollection resultColl = new AttributeExtCollection(new Attribute[] { CreateSequenceAttribute() }); resultColl = resultColl.MergeAttributeCollections(((TypeCodeImpl)m_seqType).GetClsAttributesForTypeCode()); return resultColl; }
/// <summary> /// get the custom attributes for the Type type. /// </summary> /// <param name="type">the type to get the attributes for</param> /// <param name="inherit">should attributes on inherited type also be returned</param> /// <returns></returns> public static AttributeExtCollection GetCustomAttributesForType(Type type, bool inherit) { object[] attributes = type.GetCustomAttributes(inherit); return(AttributeExtCollection.ConvertToAttributeCollection(attributes)); }
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 }); }
public object MapToIdlArray(System.Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { return new IdlArraySerializer(clsType, elemTypeAttributes, dimensions, m_config.ArraySerializationAllowNull, this); }
/// <summary> /// return the fully qualified name of typedef for the idl sequence /// </summary> public static string GetFullyQualifiedIdlTypeDefAliasForArrayType(Type arrayType, int[] dimensions, AttributeExtCollection elemTypeAttributes) { string namespaceName; string elemTypeFullQualName; string typedefName = GetTypeDefAliasForArrayType(arrayType, dimensions, elemTypeAttributes, out namespaceName, out elemTypeFullQualName); string result = MapNamespaceNameToIdl(namespaceName, "::", false); if (result.Length > 0) { result += "::"; } result = "::" + result; result += typedefName; return result; }
/// <summary> /// return the fully qualified name of typedef for the idl sequence /// </summary> public static string GetFullyQualifiedIdlTypeDefAliasForSequenceType(Type seqType, int bound, AttributeExtCollection elemTypeAttributes) { string namespaceName; string elemTypeFullQualName; string typedefName = GetTypeDefAliasForSequenceType(seqType, bound, elemTypeAttributes, out namespaceName, out elemTypeFullQualName); string result = MapNamespaceNameToIdl(namespaceName, "::", false); if (result.Length > 0) { result += "::"; } result = "::" + result; result += typedefName; return result; }
/// <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(); } }
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; }
/// <summary> /// Creates or retrieve cached Serializer for the given Type and attributes. /// </summary> internal Serializer Create(Type forType, AttributeExtCollection attributes) { return DetermineSerializer(forType, attributes); }