コード例 #1
0
 /// <summary>
 /// Returns the method name when converting an array to an IEnumerableT in compiler helper.
 /// 
 /// (not sure if this is the best place for this method...)
 /// </summary>
 public static string GetAsEnumerableTMethodName(XTypeReference sourceArrayElementType)
 {
     var convertMethodName = "AsObjectEnumerable";
     if (sourceArrayElementType.IsPrimitive)
     {
         if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable";
         else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable";
         else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable";
         else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable";
         else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable";
         else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable";
         else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable";
         else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable";
         else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable";
         else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable";
         else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable";
         else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType);
     }
     return convertMethodName;
 }
コード例 #2
0
ファイル: RCode.cs プロジェクト: Xtremrules/dot42
        /// <summary>
        /// Generate an Add opcode.
        /// </summary>
        private static RCode OpcodeForType(XTypeReference type, RCode[] opcodes)
        {
            if (type.IsInt32() || type.IsUInt32() || type.IsInt16() || type.IsUInt16() || type.IsChar() || type.IsByte() || type.IsSByte() || type.IsBoolean()) return opcodes[0];
            if (type.IsInt64() || type.IsUInt64()) return opcodes[1];
            if (type.IsFloat()) return opcodes[2];
            if (type.IsDouble()) return opcodes[3];

            XTypeDefinition typeDef;
            if (type.TryResolve(out typeDef))
            {
                if (typeDef.IsEnum)
                {
                    return OpcodeForType(typeDef.GetEnumUnderlyingType(), opcodes);
                }
            }

            throw new ArgumentException("Unsupported type " + type);
        }