Пример #1
0
        public static Method?Create(Context cx, IMethodSymbol?methodDecl)
        {
            if (methodDecl is null)
            {
                return(null);
            }

            var methodKind = methodDecl.MethodKind;

            if (methodKind == MethodKind.ExplicitInterfaceImplementation)
            {
                // Retrieve the original method kind
                methodKind = methodDecl.ExplicitInterfaceImplementations.Select(m => m.MethodKind).FirstOrDefault();
            }

            switch (methodKind)
            {
            case MethodKind.StaticConstructor:
            case MethodKind.Constructor:
                return(Constructor.Create(cx, methodDecl));

            case MethodKind.ReducedExtension:
                if (SymbolEqualityComparer.Default.Equals(methodDecl, methodDecl.ConstructedFrom))
                {
                    return(OrdinaryMethod.Create(cx, methodDecl.ReducedFrom !));
                }
                return(OrdinaryMethod.Create(cx, methodDecl.ReducedFrom !.Construct(methodDecl.TypeArguments, methodDecl.TypeArgumentNullableAnnotations)));

            case MethodKind.Ordinary:
            case MethodKind.DelegateInvoke:
                return(OrdinaryMethod.Create(cx, methodDecl));

            case MethodKind.Destructor:
                return(Destructor.Create(cx, methodDecl));

            case MethodKind.PropertyGet:
            case MethodKind.PropertySet:
                return(Accessor.GetPropertySymbol(methodDecl) is null?OrdinaryMethod.Create(cx, methodDecl) : (Method)Accessor.Create(cx, methodDecl));

            case MethodKind.EventAdd:
            case MethodKind.EventRemove:
                return(EventAccessor.Create(cx, methodDecl));

            case MethodKind.UserDefinedOperator:
            case MethodKind.BuiltinOperator:
                return(UserOperator.Create(cx, methodDecl));

            case MethodKind.Conversion:
                return(Conversion.Create(cx, methodDecl));

            case MethodKind.AnonymousFunction:
                throw new InternalError(methodDecl, "Attempt to create a lambda");

            case MethodKind.LocalFunction:
                return(LocalFunction.Create(cx, methodDecl));

            default:
                throw new InternalError(methodDecl, $"Unhandled method '{methodDecl}' of kind '{methodDecl.MethodKind}'");
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a method of the appropriate subtype.
        /// </summary>
        /// <param name="cx"></param>
        /// <param name="methodDecl"></param>
        /// <returns></returns>
        public static Method Create(Context cx, IMethodSymbol methodDecl)
        {
            if (methodDecl == null)
            {
                return(null);
            }

            var methodKind = methodDecl.MethodKind;

            if (methodKind == MethodKind.ExplicitInterfaceImplementation)
            {
                // Retrieve the original method kind
                methodKind = methodDecl.ExplicitInterfaceImplementations.Select(m => m.MethodKind).FirstOrDefault();
            }

            switch (methodKind)
            {
            case MethodKind.StaticConstructor:
            case MethodKind.Constructor:
                return(Constructor.Create(cx, methodDecl));

            case MethodKind.ReducedExtension:
            case MethodKind.Ordinary:
            case MethodKind.DelegateInvoke:
                return(OrdinaryMethod.Create(cx, methodDecl));

            case MethodKind.Destructor:
                return(Destructor.Create(cx, methodDecl));

            case MethodKind.PropertyGet:
            case MethodKind.PropertySet:
                return(methodDecl.AssociatedSymbol is null?OrdinaryMethod.Create(cx, methodDecl) : (Method)Accessor.Create(cx, methodDecl));

            case MethodKind.EventAdd:
            case MethodKind.EventRemove:
                return(EventAccessor.Create(cx, methodDecl));

            case MethodKind.UserDefinedOperator:
            case MethodKind.BuiltinOperator:
                return(UserOperator.Create(cx, methodDecl));

            case MethodKind.Conversion:
                return(Conversion.Create(cx, methodDecl));

            case MethodKind.AnonymousFunction:
                throw new InternalError(methodDecl, "Attempt to create a lambda");

            case MethodKind.LocalFunction:
                return(LocalFunction.Create(cx, methodDecl));

            default:
                throw new InternalError(methodDecl, "Unhandled method '{0}' of kind '{1}'", methodDecl, methodDecl.MethodKind);
            }
        }
Пример #3
0
 static new Destructor OriginalDefinition(Context cx, Destructor original, IMethodSymbol symbol)
 {
     return(symbol.OriginalDefinition == null || Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition));
 }
 private static new Destructor OriginalDefinition(Context cx, Destructor original, IMethodSymbol symbol)
 {
     return(symbol.OriginalDefinition is null || SymbolEqualityComparer.Default.Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition));
 }