IsAssembly() public static method

public static IsAssembly ( string file ) : bool
file string
return bool
コード例 #1
0
    public void FindInterceptor()
    {
        LogDebug("Searching for an intercepter");

        var interceptor = types.FirstOrDefault(x => x.IsInterceptor());

        if (interceptor != null)
        {
            var logMethod = interceptor.Methods.FirstOrDefault(x => x.Name == "Log");
            if (logMethod == null)
            {
                throw new WeavingException($"Could not find 'Log' method on '{interceptor.FullName}'.");
            }
            VerifyHasCorrectParameters(logMethod);
            VerifyMethodIsPublicStatic(logMethod);
            LogMethod = logMethod;
            return;
        }

        foreach (var referencePath in ReferenceCopyLocalPaths)
        {
            if (!referencePath.EndsWith(".dll") && !referencePath.EndsWith(".exe"))
            {
                continue;
            }

            var stopwatch = Stopwatch.StartNew();

            if (!Image.IsAssembly(referencePath))
            {
                LogDebug($"Skipped checking '{referencePath}' since it is not a .net assembly.");
                continue;
            }
            LogDebug($"Reading module from '{referencePath}'");
            var moduleDefinition = ReadModule(referencePath);

            stopwatch.Stop();

            interceptor = moduleDefinition
                          .GetTypes()
                          .FirstOrDefault(x => x.IsInterceptor());
            if (interceptor == null)
            {
                continue;
            }
            if (!interceptor.IsPublic)
            {
                LogInfo($"Did not use '{interceptor.FullName}' since it is not public.");
                continue;
            }
            var logMethod = interceptor.Methods.FirstOrDefault(x => x.Name == "Log");
            if (logMethod == null)
            {
                throw new WeavingException($"Could not find 'Log' method on '{interceptor.FullName}'.");
            }
            VerifyHasCorrectParameters(logMethod);
            VerifyMethodIsPublicStatic(logMethod);
            LogMethod = ModuleDefinition.ImportReference(logMethod);
            return;
        }
    }
コード例 #2
0
    public void FindInterceptor()
    {
        WriteDebug("Searching for an interceptor");

        var interceptor = types.FirstOrDefault(x => x.IsInterceptor());

        if (interceptor != null)
        {
            LogMethodUsingLong            = FindLogMethod(interceptor, LongType);
            LogWithMessageMethodUsingLong = FindLogWithMessageMethod(interceptor, LongType);

            LogMethodUsingTimeSpan            = FindLogMethod(interceptor, TimeSpanType);
            LogWithMessageMethodUsingTimeSpan = FindLogWithMessageMethod(interceptor, TimeSpanType);

            if (LogMethodUsingLong is null && LogWithMessageMethodUsingLong is null &&
                LogMethodUsingTimeSpan is null && LogWithMessageMethodUsingTimeSpan is null)
            {
                throw new WeavingException($"Could not find 'Log' method on '{interceptor.FullName}'.");
            }
            return;
        }

        foreach (var referencePath in ReferenceCopyLocalPaths)
        {
            if (!referencePath.EndsWith(".dll") && !referencePath.EndsWith(".exe"))
            {
                continue;
            }

            var stopwatch = Stopwatch.StartNew();

            if (!Image.IsAssembly(referencePath))
            {
                WriteDebug($"Skipped checking '{referencePath}' since it is not a .net assembly.");
                continue;
            }

            WriteDebug($"Reading module from '{referencePath}'");
            var moduleDefinition = ReadModule(referencePath);

            stopwatch.Stop();

            interceptor = moduleDefinition
                          .GetTypes()
                          .FirstOrDefault(x => x.IsInterceptor());
            if (interceptor is null)
            {
                continue;
            }

            if (!interceptor.IsPublic)
            {
                WriteInfo($"Did not use '{interceptor.FullName}' since it is not public.");
                continue;
            }

            var logMethodUsingLong = FindLogMethod(interceptor, LongType);
            if (logMethodUsingLong != null)
            {
                LogMethodUsingLong = ModuleDefinition.ImportReference(logMethodUsingLong);
            }

            var logWithMessageMethodUsingLong = FindLogWithMessageMethod(interceptor, LongType);
            if (logWithMessageMethodUsingLong != null)
            {
                LogWithMessageMethodUsingLong = ModuleDefinition.ImportReference(logWithMessageMethodUsingLong);
            }

            var logMethodUsingTimeSpan = FindLogMethod(interceptor, TimeSpanType);
            if (logMethodUsingTimeSpan != null)
            {
                LogMethodUsingTimeSpan = ModuleDefinition.ImportReference(logMethodUsingTimeSpan);
            }

            var logWithMessageMethodUsingTimeSpan = FindLogWithMessageMethod(interceptor, TimeSpanType);
            if (logWithMessageMethodUsingTimeSpan != null)
            {
                LogWithMessageMethodUsingTimeSpan = ModuleDefinition.ImportReference(logWithMessageMethodUsingTimeSpan);
            }

            if (LogMethodUsingLong is null && LogWithMessageMethodUsingLong is null &&
                LogMethodUsingTimeSpan is null && LogWithMessageMethodUsingTimeSpan is null)
            {
                throw new WeavingException($"Could not find 'Log' method on '{interceptor.FullName}'.");
            }
            return;
        }
    }