Ejemplo n.º 1
0
        public static bool Is(this IMethod method, ObjectMethodId id)
        {
            if (method.DeclaringType.IsInterface || method.IsStatic)
            {
                return(false);
            }

            string methodName = id.ToString();

            if (method.Name != methodName)
            {
                return(false);
            }

            switch (id)
            {
            case ObjectMethodId.Equals:
                return(method.Parameters.Count == 1 &&
                       method.Parameters[0].Type.Is(SystemTypeCode.Object) &&
                       method.Type.Is(SystemTypeCode.Boolean));

            case ObjectMethodId.GetHashCode:
                return(method.Parameters.Count == 0 &&
                       method.Type.Is(SystemTypeCode.Int32));

            case ObjectMethodId.ToString:
                return(method.Parameters.Count == 0 &&
                       method.Type.Is(SystemTypeCode.String));

            default:
                throw new ArgumentOutOfRangeException("id");
            }
        }
Ejemplo n.º 2
0
        public static void Compile(JsCompiler compiler, JsClass klass, ObjectMethodId id)
        {
            var type = klass.Type;

            if (!type.IsEnum)
            {
                throw new InvalidOperationException("Type is not enum.");
            }

            switch (id)
            {
            case ObjectMethodId.Equals:
                //TODO: implement Equals for enums here
                JsStruct.Compile(compiler, klass, id);
                break;

            case ObjectMethodId.GetHashCode:
                CompileGetHashCode(compiler, klass);
                break;

            case ObjectMethodId.ToString:
                CompileToString(compiler, klass);
                break;

            default:
                throw new ArgumentOutOfRangeException("id");
            }
        }
Ejemplo n.º 3
0
        private void CompileMethod(JsClass klass, ObjectMethodId id)
        {
            switch (klass.Type.TypeKind)
            {
            case TypeKind.Struct:
                JsStruct.Compile(this, klass, id);
                break;

            case TypeKind.Enum:
                JsEnum.Compile(this, klass, id);
                break;
            }
        }
Ejemplo n.º 4
0
        public static void Compile(JsCompiler compiler, JsClass klass, ObjectMethodId id)
        {
            switch (id)
            {
            case ObjectMethodId.Equals:
                CompileEquals(compiler, klass);
                break;

            case ObjectMethodId.GetHashCode:
                CompileGetHashCode(klass);
                break;

            case ObjectMethodId.ToString:
                // Object.ToString will be used
                break;

            default:
                throw new ArgumentOutOfRangeException("id");
            }
        }
Ejemplo n.º 5
0
 public static IMethod Find(IType objectType, ObjectMethodId id)
 {
     return(objectType.Methods.FirstOrDefault(x => x.Is(id)));
 }
Ejemplo n.º 6
0
 public AbcMethod this[ObjectMethodId id]
 {
     get { return(Methods[(int)id].Value); }
 }
Ejemplo n.º 7
0
 public AbcMethod GetMethod(ObjectMethodId id)
 {
     return(Object[id]);
 }