Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="protoCoreType"></param>
        private static void GetProtoCoreType(Type type, ref ProtoCore.Type protoCoreType)
        {
            FFIObjectMarshler marshaler;

            if (type.IsArray)
            {
                Type elemType = type.GetElementType();
                GetProtoCoreType(elemType, ref protoCoreType);
                protoCoreType.rank       += type.GetArrayRank(); //set the rank.
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsInterface && (typeof(ICollection).IsAssignableFrom(type) || typeof(IEnumerable).IsAssignableFrom(type)))
            {
                protoCoreType.rank       += 1;
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsGenericType && (typeof(ICollection).IsAssignableFrom(type) || typeof(IEnumerable).IsAssignableFrom(type)))
            {
                Type[] args  = type.GetGenericArguments();
                int    nArgs = args.Length;
                if (nArgs != 1)
                {
                    protoCoreType.Name = GetTypeName(type);
                    protoCoreType.UID  = (int)ProtoCore.PrimitiveType.kTypePointer;
                    return;
                }
                Type elemType = args[0];
                //TODO: Ideally we shouldn't be calling this method on CLRModuleType,
                //but we want to import this elemType, hence we do this.
                protoCoreType             = CLRModuleType.GetProtoCoreType(elemType, null);
                protoCoreType.rank       += 1;
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                protoCoreType = CLRModuleType.GetProtoCoreType(Nullable.GetUnderlyingType(type), null);
            }
            else if (type == typeof(object))
            {
                protoCoreType = PrimitiveMarshler.CreateType(ProtoCore.PrimitiveType.kTypeVar);
            }
            else if (type == typeof(void))
            {
                protoCoreType = PrimitiveMarshler.CreateType(ProtoCore.PrimitiveType.kTypeVoid);
            }
            else if (protoCoreType.UID == (int)ProtoCore.PrimitiveType.kTypePointer)
            {
                protoCoreType.Name = GetTypeName(type);
            }
            else if (mPrimitiveMarshalers.TryGetValue(type, out marshaler))
            {
                protoCoreType = marshaler.GetMarshaledType(type);
            }
            else
            {
                protoCoreType.Name = GetTypeName(type);
                protoCoreType.UID  = (int)ProtoCore.PrimitiveType.kTypePointer;
            }
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static ProtoCore.Type GetUserDefinedType(Type type)
 {
     ProtoCore.Type retype = PrimitiveMarshler.CreateType(ProtoCore.PrimitiveType.kTypePointer);
     GetProtoCoreType(type, ref retype);
     return(retype);
 }