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"); } }
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"); } }
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; } }
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"); } }
public static IMethod Find(IType objectType, ObjectMethodId id) { return(objectType.Methods.FirstOrDefault(x => x.Is(id))); }
public AbcMethod this[ObjectMethodId id] { get { return(Methods[(int)id].Value); } }
public AbcMethod GetMethod(ObjectMethodId id) { return(Object[id]); }