예제 #1
0
        /// <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);
        }
예제 #2
0
 public TypecodeForTypeKey(Type forType, AttributeExtCollection
                           attrs) {
     if ((forType == null) || (attrs == null)) {
         throw new INTERNAL(801, CompletionStatus.Completed_MayBe);
     }
     m_type = forType;
     m_attributes = attrs;
 }
예제 #3
0
 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;
 }
예제 #4
0
 /// <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));
 }
예제 #5
0
        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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
 public static AttributeExtCollection GetCustomAttriutesForField(FieldInfo member, bool inherit)
 {
     object[] attributes = member.GetCustomAttributes(inherit);
     return(AttributeExtCollection.ConvertToAttributeCollection(attributes));
 }
예제 #10
0
 public AttributeExtCollection(AttributeExtCollection coll)
 {
     hashCode     = coll.hashCode;
     m_attributes = (object[])coll.m_attributes.Clone();
 }
예제 #11
0
 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);
 }
예제 #12
0
 private object Unmarshal(Type type, AttributeExtCollection attributes,
                          CdrInputStream cdrIn) {
     Serializer ser = m_serFactory.Create(type, attributes);
     return ser.Deserialize(cdrIn);
 }
예제 #13
0
        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;
        }        
예제 #14
0
 /// <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;
 }
예제 #15
0
 public object MapToIdlSequence(System.Type dotNetType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elementTypeAttributes) {
     WriteInclude(dotNetType, allAttributes);
     return null;            
 }
예제 #16
0
 public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elementTypeAttributes) {
     WriteInclude(dotNetType, allAttributes);
     return null;            
 }
예제 #17
0
 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 + "\"");
 }        
예제 #18
0
        /// <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);
        }
예제 #19
0
 public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
     throw new NotSupportedException("no fwd declaration possible for this IDL-type");
 }
예제 #20
0
        /// <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);

        }
예제 #21
0
        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;
        }        
예제 #22
0
 /// <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;
 }
예제 #23
0
        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;
        }
예제 #24
0
 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);
     }
 }
예제 #25
0
 /// <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;
 }
예제 #26
0
        private void Marshal(Type type, AttributeExtCollection attributes,
                             object val, CdrOutputStream cdrOut) {
            Serializer ser = m_serFactory.Create(type, attributes);
            ser.Serialize(val, cdrOut);
 
        }
예제 #27
0
 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);
 }        
예제 #28
0
 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);
 }
예제 #29
0
 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;
 }
예제 #30
0
 /// <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());
 }
예제 #31
0
 internal override AttributeExtCollection GetClsAttributesForTypeCode()
 {
     AttributeExtCollection resultColl =
         new AttributeExtCollection(new Attribute[] { CreateSequenceAttribute() });
     resultColl = resultColl.MergeAttributeCollections(((TypeCodeImpl)m_seqType).GetClsAttributesForTypeCode());
     return resultColl;
 }
예제 #32
0
 /// <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));
 }
예제 #33
0
 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 });
 }
예제 #34
0
 public object MapToIdlArray(System.Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
     return new IdlArraySerializer(clsType, elemTypeAttributes, dimensions,
                                   m_config.ArraySerializationAllowNull,
                                   this);
 }
예제 #35
0
 /// <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;
 }
예제 #36
0
 /// <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;
 }
예제 #37
0
 /// <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();
     }
 }
예제 #38
0
 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;
 }
예제 #39
0
 /// <summary>
 /// Creates or retrieve cached Serializer for the given Type and attributes. 
 /// </summary>
 internal Serializer Create(Type forType, AttributeExtCollection attributes) {
     return DetermineSerializer(forType, attributes);
 }