├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS ├── release-drafter.yml ├── renovate.json └── workflows │ ├── ci-build.yml │ └── lock.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── image └── image.png ├── nuget.config ├── src ├── ApiGeneratorGlobalSuppressions.cs ├── Directory.build.props ├── Directory.build.targets ├── ICSharpCode.Decompiler │ ├── DecompilerException.cs │ ├── DecompilerNuGetPackageIcon.png │ ├── DisassemblerHelpers.cs │ ├── Documentation │ │ ├── GetPotentiallyNestedClassTypeReference.cs │ │ ├── IdStringMemberReference.cs │ │ ├── IdStringProvider.cs │ │ ├── XmlDocLoader.cs │ │ ├── XmlDocumentationElement.cs │ │ └── XmlDocumentationProvider.cs │ ├── ICSharpCode.Decompiler.csproj │ ├── IL │ │ ├── PrimitiveType.cs │ │ └── StackType.cs │ ├── ITextOutput.cs │ ├── Metadata │ │ ├── AssemblyReferences.cs │ │ ├── CodeMappingInfo.cs │ │ ├── CustomAttributeDecoder.cs │ │ ├── Dom.cs │ │ ├── DotNetCorePathFinder.cs │ │ ├── DotNetCorePathFinderExtensions.cs │ │ ├── EnumUnderlyingTypeResolveException.cs │ │ ├── ILOpCodes.cs │ │ ├── ILOpCodes.tt │ │ ├── LightJson │ │ │ ├── JsonArray.cs │ │ │ ├── JsonObject.cs │ │ │ ├── JsonValue.cs │ │ │ ├── JsonValueType.cs │ │ │ └── Serialization │ │ │ │ ├── JsonParseException.cs │ │ │ │ ├── JsonReader.cs │ │ │ │ ├── TextPosition.cs │ │ │ │ └── TextScanner.cs │ │ ├── MetadataExtensions.cs │ │ ├── MetadataTokenHelpers.cs │ │ ├── MethodSemanticsLookup.cs │ │ ├── OperandType.cs │ │ ├── PEFile.cs │ │ ├── SignatureBlobComparer.cs │ │ ├── UniversalAssemblyResolver.cs │ │ └── UnresolvedAssemblyNameReference.cs │ ├── NRExtensions.cs │ ├── OpCodeInfo.cs │ ├── SRMExtensions.cs │ ├── SRMHacks.cs │ ├── Semantics │ │ ├── AmbiguousResolveResult.cs │ │ ├── ArrayAccessResolveResult.cs │ │ ├── ArrayCreateResolveResult.cs │ │ ├── ByReferenceResolveResult.cs │ │ ├── ConstantResolveResult.cs │ │ ├── Conversion.cs │ │ ├── ConversionResolveResult.cs │ │ ├── ErrorResolveResult.cs │ │ ├── ForEachResolveResult.cs │ │ ├── InitializedObjectResolveResult.cs │ │ ├── InterpolatedStringResolveResult.cs │ │ ├── InvocationResolveResult.cs │ │ ├── LocalResolveResult.cs │ │ ├── MemberResolveResult.cs │ │ ├── NamedArgumentResolveResult.cs │ │ ├── NamespaceResolveResult.cs │ │ ├── OperatorResolveResult.cs │ │ ├── OutVarResolveResult.cs │ │ ├── ResolveResult.cs │ │ ├── SizeOfResolveResult.cs │ │ ├── ThisResolveResult.cs │ │ ├── ThrowResolveResult.cs │ │ ├── TupleResolveResult.cs │ │ ├── TypeIsResolveResult.cs │ │ ├── TypeOfResolveResult.cs │ │ ├── TypeResolveResult.cs │ │ └── UnknownMemberResolveResult.cs │ ├── SingleFileBundle.cs │ ├── TextLocation.cs │ ├── TypeSystem │ │ ├── Accessibility.cs │ │ ├── ApplyAttributeTypeVisitor.cs │ │ ├── ArrayType.cs │ │ ├── AssemblyQualifiedTypeName.cs │ │ ├── ByReferenceType.cs │ │ ├── ComHelper.cs │ │ ├── FullTypeName.cs │ │ ├── FunctionPointerType.cs │ │ ├── GenericContext.cs │ │ ├── IAssembly.cs │ │ ├── IAttribute.cs │ │ ├── ICodeContext.cs │ │ ├── ICompilation.cs │ │ ├── IDecompilerTypeSystem.cs │ │ ├── IEntity.cs │ │ ├── IEvent.cs │ │ ├── IField.cs │ │ ├── IFreezable.cs │ │ ├── IInterningProvider.cs │ │ ├── IMember.cs │ │ ├── IMethod.cs │ │ ├── INamedElement.cs │ │ ├── INamespace.cs │ │ ├── IParameter.cs │ │ ├── IParameterizedMember.cs │ │ ├── IProperty.cs │ │ ├── ISupportsInterning.cs │ │ ├── ISymbol.cs │ │ ├── IType.cs │ │ ├── ITypeDefinition.cs │ │ ├── ITypeParameter.cs │ │ ├── ITypeReference.cs │ │ ├── IVariable.cs │ │ ├── Implementation │ │ │ ├── AbstractFreezable.cs │ │ │ ├── AbstractType.cs │ │ │ ├── AbstractTypeParameter.cs │ │ │ ├── AttributeListBuilder.cs │ │ │ ├── BaseTypeCollector.cs │ │ │ ├── CustomAttribute.cs │ │ │ ├── DecimalConstantHelper.cs │ │ │ ├── DecoratedType.cs │ │ │ ├── DefaultAssemblyReference.cs │ │ │ ├── DefaultAttribute.cs │ │ │ ├── DefaultParameter.cs │ │ │ ├── DefaultTypeParameter.cs │ │ │ ├── DefaultVariable.cs │ │ │ ├── DummyTypeParameter.cs │ │ │ ├── FakeMember.cs │ │ │ ├── GetClassTypeReference.cs │ │ │ ├── GetMembersHelper.cs │ │ │ ├── KnownAttributes.cs │ │ │ ├── KnownTypeCache.cs │ │ │ ├── LocalFunctionMethod.cs │ │ │ ├── MergedNamespace.cs │ │ │ ├── MetadataEvent.cs │ │ │ ├── MetadataField.cs │ │ │ ├── MetadataMethod.cs │ │ │ ├── MetadataNamespace.cs │ │ │ ├── MetadataParameter.cs │ │ │ ├── MetadataProperty.cs │ │ │ ├── MetadataTypeDefinition.cs │ │ │ ├── MetadataTypeParameter.cs │ │ │ ├── MinimalCorlib.cs │ │ │ ├── NestedTypeReference.cs │ │ │ ├── NullabilityAnnotatedType.cs │ │ │ ├── PinnedType.cs │ │ │ ├── SimpleCompilation.cs │ │ │ ├── SpecializedEvent.cs │ │ │ ├── SpecializedField.cs │ │ │ ├── SpecializedMember.cs │ │ │ ├── SpecializedMethod.cs │ │ │ ├── SpecializedParameter.cs │ │ │ ├── SpecializedProperty.cs │ │ │ ├── SyntheticRangeIndexer.cs │ │ │ ├── ThreeState.cs │ │ │ ├── TypeParameterReference.cs │ │ │ ├── TypeWithElementType.cs │ │ │ └── UnknownType.cs │ │ ├── InheritanceHelper.cs │ │ ├── IntersectionType.cs │ │ ├── KnownTypeReference.cs │ │ ├── MetadataModule.cs │ │ ├── ModifiedType.cs │ │ ├── NormalizeTypeVisitor.cs │ │ ├── Nullability.cs │ │ ├── NullableType.cs │ │ ├── ParameterListComparer.cs │ │ ├── ParameterizedType.cs │ │ ├── PointerType.cs │ │ ├── ReferenceResolvingException.cs │ │ ├── ReflectionHelper.cs │ │ ├── ReflectionNameParseException.cs │ │ ├── SimpleTypeResolveContext.cs │ │ ├── SpecialType.cs │ │ ├── TaskType.cs │ │ ├── TopLevelTypeName.cs │ │ ├── TupleType.cs │ │ ├── TypeKind.cs │ │ ├── TypeParameterSubstitution.cs │ │ ├── TypeProvider.cs │ │ ├── TypeSystemExtensions.cs │ │ ├── TypeUtils.cs │ │ ├── TypeVisitor.cs │ │ └── VarArgInstanceMethod.cs │ └── Util │ │ ├── BitSet.cs │ │ ├── BusyManager.cs │ │ ├── CSharpPrimitiveCast.cs │ │ ├── CacheManager.cs │ │ ├── CallbackOnDispose.cs │ │ ├── CollectionExtensions.cs │ │ ├── EmptyList.cs │ │ ├── ExtensionMethods.cs │ │ ├── FileUtility.cs │ │ ├── GraphVizGraph.cs │ │ ├── Interval.cs │ │ ├── KeyComparer.cs │ │ ├── LazyInit.cs │ │ ├── LongDict.cs │ │ ├── LongSet.cs │ │ ├── MultiDictionary.cs │ │ ├── Platform.cs │ │ ├── ProjectedList.cs │ │ ├── ReferenceComparer.cs │ │ ├── ResXResourceWriter.cs │ │ ├── ResourcesFile.cs │ │ ├── TreeTraversal.cs │ │ ├── UnicodeNewline.cs │ │ ├── UnionFind.cs │ │ └── Win32Resources.cs ├── Pharmacist.Benchmarks │ ├── CommentGenerator.cs │ ├── Directory.build.props │ ├── NuGetHelperBenchmarks.cs │ ├── Pharmacist.Benchmarks.csproj │ ├── PlatformGeneratorBenchmarks.cs │ └── Program.cs ├── Pharmacist.Common │ ├── Pharmacist.Common.csproj │ └── SingleAwaitSubject.cs ├── Pharmacist.Console │ ├── CommandOptions │ │ ├── CommandLineOptionsBase.cs │ │ ├── CustomAssembliesCommandLineOptions.cs │ │ ├── NugetCommandLineOptions.cs │ │ └── PlatformCommandLineOptions.cs │ ├── ExitCode.cs │ ├── Pharmacist.Console.csproj │ ├── Program.cs │ └── Properties │ │ └── launchSettings.json ├── Pharmacist.Core │ ├── Comparers │ │ ├── AssemblyReferenceNameComparer.cs │ │ ├── NuGetFrameworkInRangeComparer.cs │ │ └── PackageIdentityNameComparer.cs │ ├── Extractors │ │ ├── IExtractor.cs │ │ ├── NuGetExtractor.cs │ │ └── PlatformExtractors │ │ │ ├── Android.cs │ │ │ ├── BasePlatform.cs │ │ │ ├── IPlatformExtractor.cs │ │ │ ├── Mac.cs │ │ │ ├── NetExtractorBase.cs │ │ │ ├── UWP.cs │ │ │ ├── WPF.cs │ │ │ ├── WatchOs.cs │ │ │ ├── Winforms.cs │ │ │ ├── iOS.cs │ │ │ └── tvOS.cs │ ├── Generation │ │ ├── Compilation │ │ │ ├── EventBuilderCompiler.cs │ │ │ ├── KnownTypeCache.cs │ │ │ └── PathSearchExtensions.cs │ │ ├── EventNameComparer.cs │ │ ├── Generators │ │ │ ├── DelegateGenerator.cs │ │ │ ├── EventGeneratorBase.cs │ │ │ ├── IEventGenerator.cs │ │ │ ├── InstanceEventGenerator.cs │ │ │ └── StaticEventGenerator.cs │ │ ├── ReflectionExtensions.cs │ │ ├── Resolvers │ │ │ ├── DelegateTemplateNamespaceResolver.cs │ │ │ ├── EventNamespaceResolverBase.cs │ │ │ ├── INamespaceResolver.cs │ │ │ ├── PublicEventNamespaceResolver.cs │ │ │ └── PublicStaticEventNamespaceResolver.cs │ │ ├── RoslynGeneratorExtensions.cs │ │ ├── RoslynHelpers.cs │ │ ├── TypeDefinitionNameComparer.cs │ │ ├── TypeNameComparer.cs │ │ ├── TypesMetadata.cs │ │ └── XmlSyntaxFactory.cs │ ├── Groups │ │ ├── FilesGroup.cs │ │ └── InputAssembliesGroup.cs │ ├── NuGet │ │ ├── NuGetFrameworkFolderHelper.cs │ │ ├── NuGetFrameworkHelper.cs │ │ ├── NuGetLogger.cs │ │ └── NuGetPackageHelper.cs │ ├── ObservablesForEventGenerator.cs │ ├── Pharmacist.Core.csproj │ ├── PlatformHelper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReferenceLocators │ │ ├── ReferenceLocationNotFoundException.cs │ │ └── ReferenceLocator.cs │ ├── TemplateManager.cs │ ├── Templates │ │ └── HeaderTemplate.txt │ └── Utilities │ │ ├── AssemblyHelpers.cs │ │ ├── FileSystemHelpers.cs │ │ ├── QueueExtensions.cs │ │ └── StackExtensions.cs ├── Pharmacist.IntegrationTest │ ├── InstanceClass.cs │ └── Pharmacist.IntegrationTest.csproj ├── Pharmacist.MsBuild.NuGet │ ├── MsBuildLogger.cs │ ├── Pharmacist.MsBuild.NuGet.csproj │ ├── PharmacistNuGetTask.cs │ └── targets │ │ └── Pharmacist.MSBuild.targets ├── Pharmacist.MsBuild.TargetFramework │ ├── MsBuildLogger.cs │ ├── Pharmacist.MsBuild.TargetFramework.csproj │ ├── PharmacistTargetFrameworkTask.cs │ └── targets │ │ └── Pharmacist.MSBuild.TargetFramework.targets ├── Pharmacist.Tests │ ├── API │ │ ├── ApiApprovalTests.EventBuilderProject.net6.0.approved.txt │ │ └── ApiApprovalTests.cs │ ├── AssemblyIntegrationTests.cs │ ├── IntegrationTests │ │ ├── Approved │ │ │ ├── Avalonia.0.9.12.net472.approved.txt │ │ │ ├── Avalonia.0.9.12.net5.0.approved.txt │ │ │ ├── Avalonia.0.9.12.netcoreapp3.1.approved.txt │ │ │ ├── Avalonia.0.9.12.netstandard2.0.approved.txt │ │ │ ├── Avalonia.Remote.Protocol.0.9.12.netstandard2.0.approved.txt │ │ │ ├── Platforms │ │ │ │ ├── net461.winforms.approved.txt │ │ │ │ ├── net461.wpf.approved.txt │ │ │ │ ├── net461.wpf.winforms.approved.txt │ │ │ │ ├── net462.winforms.approved.txt │ │ │ │ ├── net462.wpf.approved.txt │ │ │ │ ├── net462.wpf.winforms.approved.txt │ │ │ │ ├── net471.winforms.approved.txt │ │ │ │ ├── net471.wpf.approved.txt │ │ │ │ ├── net471.wpf.winforms.approved.txt │ │ │ │ ├── net472.winforms.approved.txt │ │ │ │ ├── net472.wpf.approved.txt │ │ │ │ ├── net472.wpf.winforms.approved.txt │ │ │ │ ├── net48.winforms.approved.txt │ │ │ │ ├── net48.wpf.approved.txt │ │ │ │ ├── net48.wpf.winforms.approved.txt │ │ │ │ ├── net5.0.winforms.approved.txt │ │ │ │ ├── net5.0.wpf.approved.txt │ │ │ │ ├── net5.0.wpf.winforms.approved.txt │ │ │ │ ├── netcoreapp3.0.winforms.approved.txt │ │ │ │ ├── netcoreapp3.0.wpf.approved.txt │ │ │ │ ├── netcoreapp3.0.wpf.winforms.approved.txt │ │ │ │ ├── netcoreapp3.1.winforms.approved.txt │ │ │ │ ├── netcoreapp3.1.wpf.approved.txt │ │ │ │ ├── netcoreapp3.1.wpf.winforms.approved.txt │ │ │ │ ├── uap10.0.16299.approved.txt │ │ │ │ ├── uap10.0.17763.approved.txt │ │ │ │ ├── uap10.0.19041.approved.txt │ │ │ │ ├── xamarin.ios10.approved.txt │ │ │ │ ├── xamarin.mac20.approved.txt │ │ │ │ └── xamarin.watchos10.approved.txt │ │ │ ├── Tizen.NET.API4.4.0.1.14152.netstandard2.0.approved.txt │ │ │ ├── Tizen.NET.API4.4.0.1.14164.netstandard2.0.approved.txt │ │ │ ├── Uno.Core.1.27.0.net472.approved.txt │ │ │ ├── Uno.Core.1.27.0.net5.0.approved.txt │ │ │ ├── Uno.Core.1.27.0.netstandard2.0.approved.txt │ │ │ ├── Uno.Core.1.27.0.uap10.0.17763.approved.txt │ │ │ ├── Uno.UI.1.44.1.monoandroid80.approved.txt │ │ │ ├── Uno.UI.1.44.1.monoandroid90.approved.txt │ │ │ ├── Uno.UI.1.44.1.net5.0.approved.txt │ │ │ ├── Uno.UI.1.44.1.netstandard2.0.approved.txt │ │ │ ├── Uno.UI.1.44.1.xamarinios10.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.monoandroid10.0.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.monoandroid90.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.xamarinios10.approved.txt │ │ │ ├── Xamarin.Essentials.1.0.0.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.monoandroid81.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.monoandroid90.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.xamarinios10.approved.txt │ │ │ ├── Xamarin.Essentials.1.6.1.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.monoandroid81.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.monoandroid90.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.xamarinios10.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.0.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.monoandroid81.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.monoandroid90.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.xamarinios10.approved.txt │ │ │ ├── Xamarin.Essentials.1.7.4.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.monoandroid10.0.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.monoandroid90.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.tizen40.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.xamarinios10.approved.txt │ │ │ ├── Xamarin.Forms.4.3.0.991250.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.monoandroid10.0.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.monoandroid90.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.tizen40.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.xamarinios10.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1687.xamarinmac20.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.monoandroid10.0.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.monoandroid90.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.netstandard2.0.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.tizen40.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.uap10.0.17763.approved.txt │ │ │ ├── Xamarin.Forms.4.8.0.1821.xamarinios10.approved.txt │ │ │ └── Xamarin.Forms.4.8.0.1821.xamarinmac20.approved.txt │ │ ├── IntegrationTestHelper.cs │ │ ├── LibraryRangeNugetTest.cs │ │ ├── PackageIdentityNuGetTest.cs │ │ └── PlatformsIntegrationTests.cs │ ├── NuGetPackageHelperTests.cs │ ├── Pharmacist.Tests.csproj │ ├── ReferenceLocationTests.cs │ ├── TestUtilities.cs │ └── xunit.runner.json ├── Pharmacist.sln ├── global.json └── stylecop.json └── version.json /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # A CODEOWNERS file uses a pattern that follows the same rules used in gitignore files. 2 | # The pattern is followed by one or more GitHub usernames or team names using the 3 | # standard @username or @org/team-name format. You can also refer to a user by an 4 | # email address that has been added to their GitHub account, for example user@example.com 5 | 6 | .github/* @reactiveui/pharmacist 7 | 8 | * @reactiveui/pharmacist 9 | version.json @reactiveui/pharmacist 10 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | template: | 2 | ## What's Changed 3 | 4 | $CHANGES 5 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["local>reactiveui/.github:renovate"] 4 | } -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | name: 'Lock Threads' 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | concurrency: 13 | group: lock 14 | 15 | jobs: 16 | action: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: dessant/lock-threads@v3 20 | with: 21 | github-token: ${{ github.token }} 22 | issue-inactive-days: '14' 23 | pr-inactive-days: '14' 24 | issue-comment: > 25 | This issue has been automatically locked since there 26 | has not been any recent activity after it was closed. 27 | Please open a new issue for related bugs. 28 | pr-comment: > 29 | This pull request has been automatically locked since there 30 | has not been any recent activity after it was closed. 31 | Please open a new issue for related bugs. -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | If you’re being harassed, noticed someone else being harassed, or have any other concerns, please contact us immediately. Your reports will be taken seriously and will not be dismissed or argued with. All members, committers and volunteers in this community are required to act according to the Code of Conduct. These guidelines help steer our interactions and strive to keep ReactiveUI a positive, growing project, community and help us provide and ensure a safe environment for everyone. When referring to a group of people, we aim to use gender-neutral terms like "team", "folks", "everyone". (For details, we recommend this post).

4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) .NET Foundation and Contributors 4 | 5 | All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /image/image.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3f05217ac6b5ac776a41905a6eca2dceb325da7f33a7ad95cd3e2b11a8ae92f5 3 | size 27152 4 | -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Directory.build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(AssemblyName) ($(TargetFramework)) 4 | 5 | 6 | 7 | $(DefineConstants);NET_45;XAML 8 | 9 | 10 | $(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP 11 | 12 | 13 | $(DefineConstants);MONO;UIKIT;COCOA 14 | 15 | 16 | $(DefineConstants);MONO;COCOA 17 | 18 | 19 | $(DefineConstants);MONO;UIKIT;COCOA 20 | 21 | 22 | $(DefineConstants);MONO;UIKIT;COCOA 23 | 24 | 25 | $(DefineConstants);MONO;ANDROID 26 | 27 | 28 | $(DefineConstants);TIZEN 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/DecompilerNuGetPackageIcon.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:9a405719968acc92a330412b4c1c8ebc8d2c30996c4027c6ba9035db2424bee6 3 | size 2454 4 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | netstandard2.0;net6.0;net7.0 6 | 7 | IL decompiler engine 8 | ic#code 9 | ILSpy 10 | Copyright 2011-2020 AlphaSierraPapa for the SharpDevelop Team 11 | en-US 12 | 13 | latest 14 | true 15 | 1701;1702;1591;1573 16 | false 17 | false 18 | false 19 | true 20 | false 21 | $(NoWarn);SYSLIB0011 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | TextTemplatingFileGenerator 32 | ILOpCodes.cs 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | True 43 | True 44 | ILOpCodes.tt 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/IL/PrimitiveType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Reflection.Metadata; 20 | 21 | namespace ICSharpCode.Decompiler.IL 22 | { 23 | public enum PrimitiveType : byte 24 | { 25 | None, 26 | I1 = PrimitiveTypeCode.SByte, 27 | I2 = PrimitiveTypeCode.Int16, 28 | I4 = PrimitiveTypeCode.Int32, 29 | I8 = PrimitiveTypeCode.Int64, 30 | R4 = PrimitiveTypeCode.Single, 31 | R8 = PrimitiveTypeCode.Double, 32 | U1 = PrimitiveTypeCode.Byte, 33 | U2 = PrimitiveTypeCode.UInt16, 34 | U4 = PrimitiveTypeCode.UInt32, 35 | U8 = PrimitiveTypeCode.UInt64, 36 | I = PrimitiveTypeCode.IntPtr, 37 | U = PrimitiveTypeCode.UIntPtr, 38 | /// Managed reference 39 | Ref = 16, 40 | /// Floating point type of unspecified size: 41 | /// usually 80 bits on x86 (when the runtime uses x87 instructions); 42 | /// but only 64-bit on x64. 43 | /// This only occurs for "conv.r.un" instructions. The C# compiler usually follows those 44 | /// with a "conv.r4" or "conv.r8" instruction to indicate the desired float type, so 45 | /// we only use this as conversion target type and don't bother tracking it as its own stack type: 46 | /// basically everything treats R identical to R8, except for the (conv.r.un + conv.r[48] => conv.r[48].un) 47 | /// combining logic which should not combine (conv.r.un + conv.r8 + conv.r4) into a single conv.r4.un. 48 | /// 49 | R = 254, 50 | Unknown = 255 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/ITextOutput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | 20 | using System.Reflection.Metadata; 21 | 22 | using ICSharpCode.Decompiler.Disassembler; 23 | using ICSharpCode.Decompiler.Metadata; 24 | using ICSharpCode.Decompiler.TypeSystem; 25 | 26 | namespace ICSharpCode.Decompiler 27 | { 28 | public interface ITextOutput 29 | { 30 | string IndentationString { get; set; } 31 | void Indent(); 32 | void Unindent(); 33 | void Write(char ch); 34 | void Write(string text); 35 | void WriteLine(); 36 | void WriteReference(OpCodeInfo opCode, bool omitSuffix = false); 37 | void WriteReference(PEFile module, Handle handle, string text, string protocol = "decompile", bool isDefinition = false); 38 | void WriteReference(IType type, string text, bool isDefinition = false); 39 | void WriteReference(IMember member, string text, bool isDefinition = false); 40 | void WriteLocalReference(string text, object reference, bool isDefinition = false); 41 | 42 | void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false); 43 | void MarkFoldEnd(); 44 | } 45 | 46 | public static class TextOutputExtensions 47 | { 48 | public static void Write(this ITextOutput output, string format, params object[] args) 49 | { 50 | output.Write(string.Format(format, args)); 51 | } 52 | 53 | public static void WriteLine(this ITextOutput output, string text) 54 | { 55 | output.Write(text); 56 | output.WriteLine(); 57 | } 58 | 59 | public static void WriteLine(this ITextOutput output, string format, params object[] args) 60 | { 61 | output.WriteLine(string.Format(format, args)); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Siegfried Pammer 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | namespace ICSharpCode.Decompiler.Metadata 23 | { 24 | [Serializable] 25 | public class EnumUnderlyingTypeResolveException : Exception 26 | { 27 | public EnumUnderlyingTypeResolveException() { } 28 | public EnumUnderlyingTypeResolveException(string message) : base(message) { } 29 | public EnumUnderlyingTypeResolveException(string message, Exception inner) : base(message, inner) { } 30 | protected EnumUnderlyingTypeResolveException( 31 | SerializationInfo info, 32 | StreamingContext context) : base(info, context) { } 33 | } 34 | 35 | [Serializable] 36 | public class PEFileNotSupportedException : Exception 37 | { 38 | public PEFileNotSupportedException() { } 39 | public PEFileNotSupportedException(string message) : base(message) { } 40 | public PEFileNotSupportedException(string message, Exception inner) : base(message, inner) { } 41 | protected PEFileNotSupportedException( 42 | SerializationInfo info, 43 | StreamingContext context) : base(info, context) { } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Metadata/LightJson/JsonValueType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace LightJson 5 | { 6 | /// 7 | /// Enumerates the types of Json values. 8 | /// 9 | internal enum JsonValueType : byte 10 | { 11 | /// 12 | /// A null value. 13 | /// 14 | Null = 0, 15 | 16 | /// 17 | /// A boolean value. 18 | /// 19 | Boolean, 20 | 21 | /// 22 | /// A number value. 23 | /// 24 | Number, 25 | 26 | /// 27 | /// A string value. 28 | /// 29 | String, 30 | 31 | /// 32 | /// An object value. 33 | /// 34 | Object, 35 | 36 | /// 37 | /// An array value. 38 | /// 39 | Array, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Metadata/LightJson/Serialization/TextPosition.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace LightJson.Serialization 5 | { 6 | /// 7 | /// Represents a position within a plain text resource. 8 | /// 9 | internal struct TextPosition 10 | { 11 | /// 12 | /// The column position, 0-based. 13 | /// 14 | public long Column; 15 | 16 | /// 17 | /// The line position, 0-based. 18 | /// 19 | public long Line; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Metadata/MetadataTokenHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Siegfried Pammer 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Reflection.Metadata; 21 | using System.Reflection.Metadata.Ecma335; 22 | 23 | namespace ICSharpCode.Decompiler.Metadata 24 | { 25 | public static class MetadataTokenHelpers 26 | { 27 | public static EntityHandle? TryAsEntityHandle(int metadataToken) 28 | { 29 | // SRM would interpret negative token values as virtual tokens, 30 | // but that causes problems later on. 31 | if (metadataToken < 0) 32 | return null; 33 | try 34 | { 35 | return MetadataTokens.EntityHandle(metadataToken); 36 | } 37 | catch (ArgumentException) 38 | { 39 | return null; 40 | } 41 | } 42 | 43 | public static EntityHandle EntityHandleOrNil(int metadataToken) 44 | { 45 | // SRM would interpret negative token values as virtual tokens, 46 | // but that causes problems later on. 47 | if (metadataToken < 0) 48 | return MetadataTokens.EntityHandle(0); 49 | try 50 | { 51 | return MetadataTokens.EntityHandle(metadataToken); 52 | } 53 | catch (ArgumentException) 54 | { 55 | return MetadataTokens.EntityHandle(0); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Metadata/UnresolvedAssemblyNameReference.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Siegfried Pammer 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.Linq; 21 | 22 | namespace ICSharpCode.Decompiler.Metadata 23 | { 24 | public sealed class UnresolvedAssemblyNameReference 25 | { 26 | public string FullName { get; } 27 | 28 | public bool HasErrors => Messages.Any(m => m.Item1 == MessageKind.Error); 29 | 30 | public List<(MessageKind, string)> Messages { get; } = new List<(MessageKind, string)>(); 31 | 32 | public UnresolvedAssemblyNameReference(string fullName) 33 | { 34 | this.FullName = fullName; 35 | } 36 | } 37 | 38 | public enum MessageKind { Error, Warning, Info } 39 | } 40 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/SRMHacks.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Immutable; 2 | using System.Reflection.Metadata; 3 | 4 | namespace ICSharpCode.Decompiler 5 | { 6 | public static partial class SRMExtensions 7 | { 8 | public static ImmutableArray GetMethodImplementations( 9 | this MethodDefinitionHandle handle, MetadataReader reader) 10 | { 11 | var resultBuilder = ImmutableArray.CreateBuilder(); 12 | var typeDefinition = reader.GetTypeDefinition(reader.GetMethodDefinition(handle) 13 | .GetDeclaringType()); 14 | 15 | foreach (var methodImplementationHandle in typeDefinition.GetMethodImplementations()) 16 | { 17 | var methodImplementation = reader.GetMethodImplementation(methodImplementationHandle); 18 | if (methodImplementation.MethodBody == handle) 19 | { 20 | resultBuilder.Add(methodImplementationHandle); 21 | } 22 | } 23 | 24 | return resultBuilder.ToImmutable(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/AmbiguousResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | /// 24 | /// Represents an ambiguous type resolve result. 25 | /// 26 | public class AmbiguousTypeResolveResult : TypeResolveResult 27 | { 28 | public AmbiguousTypeResolveResult(IType type) : base(type) 29 | { 30 | } 31 | 32 | public override bool IsError { 33 | get { return true; } 34 | } 35 | } 36 | 37 | /// 38 | /// Represents an ambiguous field/property/event access. 39 | /// 40 | public class AmbiguousMemberResolveResult : MemberResolveResult 41 | { 42 | public AmbiguousMemberResolveResult(ResolveResult targetResult, IMember member) : base(targetResult, member) 43 | { 44 | } 45 | 46 | public override bool IsError { 47 | get { return true; } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ArrayAccessResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | 23 | using ICSharpCode.Decompiler.TypeSystem; 24 | 25 | namespace ICSharpCode.Decompiler.Semantics 26 | { 27 | /// 28 | /// Resolve result representing an array access. 29 | /// 30 | public class ArrayAccessResolveResult : ResolveResult 31 | { 32 | public readonly ResolveResult Array; 33 | public readonly IList Indexes; 34 | 35 | public ArrayAccessResolveResult(IType elementType, ResolveResult array, IList indexes) : base(elementType) 36 | { 37 | if (array == null) 38 | throw new ArgumentNullException(nameof(array)); 39 | if (indexes == null) 40 | throw new ArgumentNullException(nameof(indexes)); 41 | this.Array = array; 42 | this.Indexes = indexes; 43 | } 44 | 45 | public override IEnumerable GetChildResults() 46 | { 47 | return new[] { Array }.Concat(Indexes); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ArrayCreateResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | 23 | using ICSharpCode.Decompiler.TypeSystem; 24 | 25 | namespace ICSharpCode.Decompiler.Semantics 26 | { 27 | /// 28 | /// Resolve result representing an array creation. 29 | /// 30 | public class ArrayCreateResolveResult : ResolveResult 31 | { 32 | /// 33 | /// Gets the size arguments. 34 | /// 35 | public readonly IReadOnlyList SizeArguments; 36 | 37 | /// 38 | /// Gets the initializer elements. 39 | /// This field may be null if no initializer was specified. 40 | /// 41 | public readonly IReadOnlyList InitializerElements; 42 | 43 | public ArrayCreateResolveResult(IType arrayType, IReadOnlyList sizeArguments, IReadOnlyList initializerElements) 44 | : base(arrayType) 45 | { 46 | if (sizeArguments == null) 47 | throw new ArgumentNullException(nameof(sizeArguments)); 48 | this.SizeArguments = sizeArguments; 49 | this.InitializerElements = initializerElements; 50 | } 51 | 52 | public override IEnumerable GetChildResults() 53 | { 54 | if (InitializerElements != null) 55 | return SizeArguments.Concat(InitializerElements); 56 | else 57 | return SizeArguments; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ByReferenceResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.Globalization; 21 | using System.Linq; 22 | 23 | using ICSharpCode.Decompiler.TypeSystem; 24 | 25 | namespace ICSharpCode.Decompiler.Semantics 26 | { 27 | /// 28 | /// Represents the resolve result of an 'ref x', 'in x' or 'out x' expression. 29 | /// 30 | public class ByReferenceResolveResult : ResolveResult 31 | { 32 | public ReferenceKind ReferenceKind { get; } 33 | public bool IsOut => ReferenceKind == ReferenceKind.Out; 34 | public bool IsRef => ReferenceKind == ReferenceKind.Ref; 35 | public bool IsIn => ReferenceKind == ReferenceKind.In; 36 | 37 | public readonly ResolveResult ElementResult; 38 | 39 | public ByReferenceResolveResult(ResolveResult elementResult, ReferenceKind kind) 40 | : this(elementResult.Type, kind) 41 | { 42 | this.ElementResult = elementResult; 43 | } 44 | 45 | public ByReferenceResolveResult(IType elementType, ReferenceKind kind) 46 | : base(new ByReferenceType(elementType)) 47 | { 48 | this.ReferenceKind = kind; 49 | } 50 | 51 | public IType ElementType { 52 | get { return ((ByReferenceType)this.Type).ElementType; } 53 | } 54 | 55 | public override IEnumerable GetChildResults() 56 | { 57 | if (ElementResult != null) 58 | return new[] { ElementResult }; 59 | else 60 | return Enumerable.Empty(); 61 | } 62 | 63 | public override string ToString() 64 | { 65 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1} {2}]", GetType().Name, ReferenceKind.ToString().ToLowerInvariant(), ElementType); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ConstantResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Globalization; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | /// 26 | /// ResolveResult representing a compile-time constant. 27 | /// Note: this class is mainly used for literals; there may be other ResolveResult classes 28 | /// which are compile-time constants as well. 29 | /// For example, a reference to a const field results in a . 30 | /// 31 | /// Check to determine is a resolve result is a constant. 32 | /// 33 | public class ConstantResolveResult : ResolveResult 34 | { 35 | object constantValue; 36 | 37 | public ConstantResolveResult(IType type, object constantValue) : base(type) 38 | { 39 | this.constantValue = constantValue; 40 | } 41 | 42 | public override bool IsCompileTimeConstant { 43 | get { return true; } 44 | } 45 | 46 | public override object ConstantValue { 47 | get { return constantValue; } 48 | } 49 | 50 | public override string ToString() 51 | { 52 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1} = {2}]", GetType().Name, this.Type, constantValue); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ErrorResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.CSharp.Syntax; 20 | using ICSharpCode.Decompiler.TypeSystem; 21 | 22 | namespace ICSharpCode.Decompiler.Semantics 23 | { 24 | /// 25 | /// Represents a resolve error. 26 | /// 27 | /// Note: some errors are represented by other classes; for example a may 28 | /// be erroneous if the conversion is invalid. 29 | /// 30 | /// . 31 | public class ErrorResolveResult : ResolveResult 32 | { 33 | /// 34 | /// Gets an ErrorResolveResult instance with Type = SpecialType.UnknownType. 35 | /// 36 | public static readonly ErrorResolveResult UnknownError = new ErrorResolveResult(SpecialType.UnknownType); 37 | 38 | public ErrorResolveResult(IType type) : base(type) 39 | { 40 | } 41 | 42 | public ErrorResolveResult(IType type, string message, TextLocation location) : base(type) 43 | { 44 | this.Message = message; 45 | this.Location = location; 46 | } 47 | 48 | public override bool IsError { 49 | get { return true; } 50 | } 51 | 52 | public string Message { get; private set; } 53 | 54 | public TextLocation Location { get; private set; } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/InitializedObjectResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | /// 24 | /// Refers to the object that is currently being initialized. 25 | /// Used within . 26 | /// 27 | public class InitializedObjectResolveResult : ResolveResult 28 | { 29 | public InitializedObjectResolveResult(IType type) : base(type) 30 | { 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/InterpolatedStringResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Siegfried Pammer 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | public class InterpolatedStringResolveResult : ResolveResult 26 | { 27 | public readonly string FormatString; 28 | public readonly ResolveResult[] Arguments; 29 | 30 | public InterpolatedStringResolveResult(IType stringType, string formatString, params ResolveResult[] arguments) 31 | : base(stringType) 32 | { 33 | FormatString = formatString; 34 | Arguments = arguments; 35 | } 36 | 37 | public override IEnumerable GetChildResults() 38 | { 39 | return Arguments; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/LocalResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Globalization; 21 | 22 | using ICSharpCode.Decompiler.TypeSystem; 23 | 24 | namespace ICSharpCode.Decompiler.Semantics 25 | { 26 | /// 27 | /// Represents a local variable or parameter. 28 | /// 29 | public class LocalResolveResult : ResolveResult 30 | { 31 | readonly IVariable variable; 32 | 33 | public LocalResolveResult(IVariable variable) 34 | : base(UnpackTypeIfByRefParameter(variable)) 35 | { 36 | this.variable = variable; 37 | } 38 | 39 | static IType UnpackTypeIfByRefParameter(IVariable variable) 40 | { 41 | if (variable == null) 42 | throw new ArgumentNullException(nameof(variable)); 43 | var type = variable.Type; 44 | if (type.Kind == TypeKind.ByReference) 45 | { 46 | var p = variable as IParameter; 47 | if (p != null && p.ReferenceKind != ReferenceKind.None) 48 | return ((ByReferenceType)type).ElementType; 49 | } 50 | return type; 51 | } 52 | 53 | public IVariable Variable { 54 | get { return variable; } 55 | } 56 | 57 | public bool IsParameter { 58 | get { return variable is IParameter; } 59 | } 60 | 61 | public override bool IsCompileTimeConstant { 62 | get { return variable.IsConst; } 63 | } 64 | 65 | public override object ConstantValue { 66 | get { return IsParameter ? null : variable.GetConstantValue(); } 67 | } 68 | 69 | public override string ToString() 70 | { 71 | return string.Format(CultureInfo.InvariantCulture, "[LocalResolveResult {0}]", variable); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/NamespaceResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Globalization; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | /// 26 | /// Represents that an expression resolved to a namespace. 27 | /// 28 | public class NamespaceResolveResult : ResolveResult 29 | { 30 | readonly INamespace ns; 31 | 32 | public NamespaceResolveResult(INamespace ns) : base(SpecialType.NoType) 33 | { 34 | this.ns = ns; 35 | } 36 | 37 | public INamespace Namespace { 38 | get { return ns; } 39 | } 40 | 41 | public string NamespaceName { 42 | get { return ns.FullName; } 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1}]", GetType().Name, ns); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/OutVarResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | /// 24 | /// Represents the implicitly-typed "out var". 25 | /// Special-cased in overload resolution to be compatible with any out-parameter. 26 | /// 27 | class OutVarResolveResult : ResolveResult 28 | { 29 | public static readonly OutVarResolveResult Instance = new OutVarResolveResult(); 30 | 31 | public OutVarResolveResult() : base(SpecialType.NoType) { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | 23 | using ICSharpCode.Decompiler.TypeSystem; 24 | 25 | namespace ICSharpCode.Decompiler.Semantics 26 | { 27 | /// 28 | /// Represents the result of resolving an expression. 29 | /// 30 | public class ResolveResult 31 | { 32 | readonly IType type; 33 | 34 | public ResolveResult(IType type) 35 | { 36 | if (type == null) 37 | throw new ArgumentNullException(nameof(type)); 38 | this.type = type; 39 | } 40 | 41 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", 42 | Justification = "Unrelated to object.GetType()")] 43 | public IType Type { 44 | get { return type; } 45 | } 46 | 47 | public virtual bool IsCompileTimeConstant { 48 | get { return false; } 49 | } 50 | 51 | public virtual object ConstantValue { 52 | get { return null; } 53 | } 54 | 55 | public virtual bool IsError { 56 | get { return false; } 57 | } 58 | 59 | public override string ToString() 60 | { 61 | return "[" + GetType().Name + " " + type + "]"; 62 | } 63 | 64 | public virtual IEnumerable GetChildResults() 65 | { 66 | return Enumerable.Empty(); 67 | } 68 | 69 | public virtual ResolveResult ShallowClone() 70 | { 71 | return (ResolveResult)MemberwiseClone(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/SizeOfResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | /// 26 | /// Represents the 'sizeof'. 27 | /// 28 | public class SizeOfResolveResult : ResolveResult 29 | { 30 | readonly IType referencedType; 31 | readonly int? constantValue; 32 | 33 | public SizeOfResolveResult(IType int32, IType referencedType, int? constantValue) 34 | : base(int32) 35 | { 36 | if (referencedType == null) 37 | throw new ArgumentNullException(nameof(referencedType)); 38 | this.referencedType = referencedType; 39 | this.constantValue = constantValue; 40 | } 41 | 42 | /// 43 | /// The type referenced by the 'sizeof'. 44 | /// 45 | public IType ReferencedType { 46 | get { return referencedType; } 47 | } 48 | 49 | public override bool IsCompileTimeConstant { 50 | get { 51 | return constantValue != null; 52 | } 53 | } 54 | 55 | public override object ConstantValue { 56 | get { 57 | return constantValue; 58 | } 59 | } 60 | 61 | public override bool IsError { 62 | get { 63 | return referencedType.IsReferenceType != false; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ThisResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | /// 24 | /// Represents the 'this' reference. 25 | /// Also used for the 'base' reference. 26 | /// 27 | public class ThisResolveResult : ResolveResult 28 | { 29 | bool causesNonVirtualInvocation; 30 | 31 | public ThisResolveResult(IType type, bool causesNonVirtualInvocation = false) : base(type) 32 | { 33 | this.causesNonVirtualInvocation = causesNonVirtualInvocation; 34 | } 35 | 36 | /// 37 | /// Gets whether this resolve result causes member invocations to be non-virtual. 38 | /// 39 | public bool CausesNonVirtualInvocation { 40 | get { return causesNonVirtualInvocation; } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/ThrowResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | class ThrowResolveResult : ResolveResult 24 | { 25 | public ThrowResolveResult() : base(SpecialType.NoType) 26 | { 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/TupleResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.Collections.Immutable; 21 | using System.Linq; 22 | 23 | using ICSharpCode.Decompiler.TypeSystem; 24 | 25 | namespace ICSharpCode.Decompiler.Semantics 26 | { 27 | /// 28 | /// Resolve result for a C# 7 tuple literal. 29 | /// 30 | public class TupleResolveResult : ResolveResult 31 | { 32 | public ImmutableArray Elements { get; } 33 | 34 | public TupleResolveResult(ICompilation compilation, 35 | ImmutableArray elements, 36 | ImmutableArray elementNames = default(ImmutableArray), 37 | IModule valueTupleAssembly = null) 38 | : base(GetTupleType(compilation, elements, elementNames, valueTupleAssembly)) 39 | { 40 | this.Elements = elements; 41 | } 42 | 43 | public override IEnumerable GetChildResults() 44 | { 45 | return Elements; 46 | } 47 | 48 | static IType GetTupleType(ICompilation compilation, ImmutableArray elements, ImmutableArray elementNames, IModule valueTupleAssembly) 49 | { 50 | if (elements.Any(e => e.Type.Kind == TypeKind.None || e.Type.Kind == TypeKind.Null)) 51 | return SpecialType.NoType; 52 | else 53 | return new TupleType(compilation, elements.Select(e => e.Type).ToImmutableArray(), elementNames, valueTupleAssembly); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/TypeIsResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | /// 26 | /// Resolve result for a C# 'is' expression. 27 | /// "Input is TargetType". 28 | /// 29 | public class TypeIsResolveResult : ResolveResult 30 | { 31 | public readonly ResolveResult Input; 32 | /// 33 | /// Type that is being compared with. 34 | /// 35 | public readonly IType TargetType; 36 | 37 | public TypeIsResolveResult(ResolveResult input, IType targetType, IType booleanType) 38 | : base(booleanType) 39 | { 40 | if (input == null) 41 | throw new ArgumentNullException(nameof(input)); 42 | if (targetType == null) 43 | throw new ArgumentNullException(nameof(targetType)); 44 | this.Input = input; 45 | this.TargetType = targetType; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/TypeOfResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using ICSharpCode.Decompiler.TypeSystem; 22 | 23 | namespace ICSharpCode.Decompiler.Semantics 24 | { 25 | /// 26 | /// Represents the 'typeof'. 27 | /// 28 | public class TypeOfResolveResult : ResolveResult 29 | { 30 | readonly IType referencedType; 31 | 32 | public TypeOfResolveResult(IType systemType, IType referencedType) 33 | : base(systemType) 34 | { 35 | if (referencedType == null) 36 | throw new ArgumentNullException(nameof(referencedType)); 37 | this.referencedType = referencedType; 38 | } 39 | 40 | /// 41 | /// The type referenced by the 'typeof'. 42 | /// 43 | public IType ReferencedType { 44 | get { return referencedType; } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Semantics/TypeResolveResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.TypeSystem; 20 | 21 | namespace ICSharpCode.Decompiler.Semantics 22 | { 23 | /// 24 | /// The resolved expression refers to a type name. 25 | /// 26 | public class TypeResolveResult : ResolveResult 27 | { 28 | public TypeResolveResult(IType type) 29 | : base(type) 30 | { 31 | } 32 | 33 | public override bool IsError { 34 | get { return this.Type.Kind == TypeKind.Unknown; } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/ComHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Helper methods for COM. 23 | /// 24 | public static class ComHelper 25 | { 26 | /// 27 | /// Gets whether the specified type is imported from COM. 28 | /// 29 | public static bool IsComImport(ITypeDefinition typeDefinition) 30 | { 31 | return typeDefinition != null 32 | && typeDefinition.Kind == TypeKind.Interface 33 | && typeDefinition.HasAttribute(KnownAttribute.ComImport, inherit: false); 34 | } 35 | 36 | /// 37 | /// Gets the CoClass of the specified COM interface. 38 | /// 39 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Co", 40 | Justification = "Consistent with CoClassAttribute")] 41 | public static IType GetCoClass(ITypeDefinition typeDefinition) 42 | { 43 | if (typeDefinition == null) 44 | return SpecialType.UnknownType; 45 | var coClassAttribute = typeDefinition.GetAttribute(KnownAttribute.CoClass, inherit: false); 46 | if (coClassAttribute != null && coClassAttribute.FixedArguments.Length == 1) 47 | { 48 | if (coClassAttribute.FixedArguments[0].Value is IType ty) 49 | return ty; 50 | } 51 | return SpecialType.UnknownType; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Immutable; 20 | using System.Reflection.Metadata; 21 | 22 | namespace ICSharpCode.Decompiler.TypeSystem 23 | { 24 | /// 25 | /// Represents an attribute. 26 | /// 27 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] 28 | public interface IAttribute 29 | { 30 | /// 31 | /// Gets the type of the attribute. 32 | /// 33 | IType AttributeType { get; } 34 | 35 | /// 36 | /// Gets the constructor being used. 37 | /// This property may return null if no matching constructor was found. 38 | /// 39 | IMethod Constructor { get; } 40 | 41 | /// 42 | /// Gets whether there were errors decoding the attribute. 43 | /// 44 | bool HasDecodeErrors { get; } 45 | 46 | /// 47 | /// Gets the positional arguments. 48 | /// 49 | ImmutableArray> FixedArguments { get; } 50 | 51 | /// 52 | /// Gets the named arguments passed to the attribute. 53 | /// 54 | ImmutableArray> NamedArguments { get; } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem 22 | { 23 | public interface ICodeContext : ITypeResolveContext 24 | { 25 | /// 26 | /// Gets all currently visible local variables and lambda parameters. 27 | /// Does not include method parameters. 28 | /// 29 | IEnumerable LocalVariables { get; } 30 | 31 | /// 32 | /// Gets whether the context is within a lambda expression or anonymous method. 33 | /// 34 | bool IsWithinLambdaExpression { get; } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Main interface for the decompiler type system. 23 | /// 24 | /// The MetadataModule class allows decoding/resolving metadata tokens into type system entities. 25 | /// 26 | public interface IDecompilerTypeSystem : ICompilation 27 | { 28 | new MetadataModule MainModule { get; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IEvent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | public interface IEvent : IMember 22 | { 23 | bool CanAdd { get; } 24 | bool CanRemove { get; } 25 | bool CanInvoke { get; } 26 | 27 | IMethod AddAccessor { get; } 28 | IMethod RemoveAccessor { get; } 29 | IMethod InvokeAccessor { get; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IField.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Represents a field or constant. 23 | /// 24 | public interface IField : IMember, IVariable 25 | { 26 | /// 27 | /// Gets the name of the field. 28 | /// 29 | new string Name { get; } // solve ambiguity between IMember.Name and IVariable.Name 30 | 31 | /// 32 | /// Gets whether this field is readonly. 33 | /// 34 | bool IsReadOnly { get; } 35 | 36 | /// 37 | /// Gets whether this field is volatile. 38 | /// 39 | bool IsVolatile { get; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | public interface IFreezable 22 | { 23 | /// 24 | /// Gets if this instance is frozen. Frozen instances are immutable and thus thread-safe. 25 | /// 26 | bool IsFrozen { get; } 27 | 28 | /// 29 | /// Freezes this instance. 30 | /// 31 | void Freeze(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/INamedElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | public interface INamedElement 22 | { 23 | /// 24 | /// Gets the fully qualified name of the class the return type is pointing to. 25 | /// 26 | /// 27 | /// "System.Int32[]" for int[]
28 | /// "System.Collections.Generic.List" for List<string> 29 | /// "System.Environment.SpecialFolder" for Environment.SpecialFolder 30 | ///
31 | string FullName { get; } 32 | 33 | /// 34 | /// Gets the short name of the class the return type is pointing to. 35 | /// 36 | /// 37 | /// "Int32[]" for int[]
38 | /// "List" for List<string> 39 | /// "SpecialFolder" for Environment.SpecialFolder 40 | ///
41 | string Name { get; } 42 | 43 | /// 44 | /// Gets the full reflection name of the element. 45 | /// 46 | /// 47 | /// For types, the reflection name can be parsed back into a ITypeReference by using 48 | /// . 49 | /// 50 | /// 51 | /// "System.Int32[]" for int[]
52 | /// "System.Int32[][,]" for C# int[,][]
53 | /// "System.Collections.Generic.List`1[[System.String]]" for List<string> 54 | /// "System.Environment+SpecialFolder" for Environment.SpecialFolder 55 | ///
56 | string ReflectionName { get; } 57 | 58 | /// 59 | /// Gets the full name of the namespace containing this entity. 60 | /// 61 | string Namespace { get; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem 22 | { 23 | /// 24 | /// Represents a method or property. 25 | /// 26 | public interface IParameterizedMember : IMember 27 | { 28 | IReadOnlyList Parameters { get; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IProperty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Represents a property or indexer. 23 | /// 24 | public interface IProperty : IParameterizedMember 25 | { 26 | bool CanGet { get; } 27 | bool CanSet { get; } 28 | 29 | IMethod Getter { get; } 30 | IMethod Setter { get; } 31 | 32 | bool IsIndexer { get; } 33 | 34 | /// 35 | /// Gets whether the return type is 'ref readonly'. 36 | /// 37 | bool ReturnTypeIsRefReadOnly { get; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Interface for TypeSystem objects that support interning. 23 | /// See for more information. 24 | /// 25 | public interface ISupportsInterning 26 | { 27 | /// 28 | /// Gets a hash code for interning. 29 | /// 30 | int GetHashCodeForInterning(); 31 | 32 | /// 33 | /// Equality test for interning. 34 | /// 35 | bool EqualsForInterning(ISupportsInterning other); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/IVariable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem 20 | { 21 | /// 22 | /// Represents a variable (name/type pair). 23 | /// 24 | public interface IVariable : ISymbol 25 | { 26 | /// 27 | /// Gets the name of the variable. 28 | /// 29 | new string Name { get; } 30 | 31 | /// 32 | /// Gets the type of the variable. 33 | /// 34 | IType Type { get; } 35 | 36 | /// 37 | /// Gets whether this variable is a constant (C#-like const). 38 | /// 39 | bool IsConst { get; } 40 | 41 | /// 42 | /// If this field is a constant, retrieves the value. 43 | /// For parameters, this is the default value. 44 | /// 45 | object GetConstantValue(bool throwOnInvalidMetadata = false); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultVariable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation 22 | { 23 | /// 24 | /// Default implementation of . 25 | /// 26 | public sealed class DefaultVariable : IVariable 27 | { 28 | readonly string name; 29 | readonly IType type; 30 | readonly object constantValue; 31 | readonly bool isConst; 32 | 33 | public DefaultVariable(IType type, string name) 34 | { 35 | if (type == null) 36 | throw new ArgumentNullException(nameof(type)); 37 | if (name == null) 38 | throw new ArgumentNullException(nameof(name)); 39 | this.type = type; 40 | this.name = name; 41 | } 42 | 43 | public DefaultVariable(IType type, string name, 44 | bool isConst = false, object constantValue = null) 45 | : this(type, name) 46 | { 47 | this.isConst = isConst; 48 | this.constantValue = constantValue; 49 | } 50 | 51 | public string Name { 52 | get { return name; } 53 | } 54 | 55 | public IType Type { 56 | get { return type; } 57 | } 58 | 59 | public bool IsConst { 60 | get { return isConst; } 61 | } 62 | 63 | public object GetConstantValue(bool throwOnInvalidMetadata) 64 | { 65 | return constantValue; 66 | } 67 | 68 | public SymbolKind SymbolKind { 69 | get { return SymbolKind.Variable; } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using ICSharpCode.Decompiler.Util; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation 22 | { 23 | /// 24 | /// Cache for KnownTypeReferences. 25 | /// 26 | sealed class KnownTypeCache 27 | { 28 | readonly ICompilation compilation; 29 | readonly IType[] knownTypes = new IType[KnownTypeReference.KnownTypeCodeCount]; 30 | 31 | public KnownTypeCache(ICompilation compilation) 32 | { 33 | this.compilation = compilation; 34 | } 35 | 36 | public IType FindType(KnownTypeCode typeCode) 37 | { 38 | var type = LazyInit.VolatileRead(ref knownTypes[(int)typeCode]); 39 | if (type != null) 40 | { 41 | return type; 42 | } 43 | return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode)); 44 | } 45 | 46 | IType SearchType(KnownTypeCode typeCode) 47 | { 48 | var typeRef = KnownTypeReference.Get(typeCode); 49 | if (typeRef == null) 50 | return SpecialType.UnknownType; 51 | var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); 52 | foreach (var asm in compilation.Modules) 53 | { 54 | var typeDef = asm.GetTypeDefinition(typeName); 55 | if (typeDef != null) 56 | return typeDef; 57 | } 58 | return new UnknownType(typeName); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Siegfried Pammer 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using SRM = System.Reflection.Metadata; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation 22 | { 23 | public sealed class PinnedType : TypeWithElementType 24 | { 25 | public PinnedType(IType elementType) 26 | : base(elementType) 27 | { 28 | } 29 | 30 | public override string NameSuffix => " pinned"; 31 | 32 | public override bool? IsReferenceType => elementType.IsReferenceType; 33 | public override bool IsByRefLike => elementType.IsByRefLike; 34 | 35 | public override TypeKind Kind => TypeKind.Other; 36 | 37 | public override IType VisitChildren(TypeVisitor visitor) 38 | { 39 | var newType = elementType.AcceptVisitor(visitor); 40 | if (newType == elementType) 41 | return this; 42 | return new PinnedType(newType); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Implementation/ThreeState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation 20 | { 21 | /// 22 | /// Constants used instead of bool? 23 | /// in multithreaded code, as bool? might produce torn reads. 24 | /// 25 | static class ThreeState 26 | { 27 | public const byte Unknown = 0; 28 | public const byte False = 1; 29 | public const byte True = 2; 30 | 31 | public static byte From(bool value) => value ? True : False; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Implementation/TypeWithElementType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation 22 | { 23 | public abstract class TypeWithElementType : AbstractType 24 | { 25 | protected IType elementType; 26 | 27 | protected TypeWithElementType(IType elementType) 28 | { 29 | if (elementType == null) 30 | throw new ArgumentNullException(nameof(elementType)); 31 | this.elementType = elementType; 32 | } 33 | 34 | public override string Name { 35 | get { return elementType.Name + NameSuffix; } 36 | } 37 | 38 | public override string Namespace { 39 | get { return elementType.Namespace; } 40 | } 41 | 42 | public override string FullName { 43 | get { return elementType.FullName + NameSuffix; } 44 | } 45 | 46 | public override string ReflectionName { 47 | get { return elementType.ReflectionName + NameSuffix; } 48 | } 49 | 50 | public override string ToString() 51 | { 52 | return elementType.ToString() + NameSuffix; 53 | } 54 | 55 | public abstract string NameSuffix { get; } 56 | 57 | public IType ElementType { 58 | get { return elementType; } 59 | } 60 | 61 | // Force concrete implementations to override VisitChildren - the base implementation 62 | // in AbstractType assumes there are no children, but we know there is (at least) 1. 63 | public abstract override IType VisitChildren(TypeVisitor visitor); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/Nullability.cs: -------------------------------------------------------------------------------- 1 | namespace ICSharpCode.Decompiler.TypeSystem 2 | { 3 | public enum Nullability : byte 4 | { 5 | Oblivious = 0, 6 | NotNullable = 1, 7 | Nullable = 2 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/TypeSystem/ReflectionNameParseException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | namespace ICSharpCode.Decompiler.TypeSystem 23 | { 24 | /// 25 | /// Represents an error while parsing a reflection name. 26 | /// 27 | [Serializable] 28 | public class ReflectionNameParseException : Exception 29 | { 30 | int position; 31 | 32 | public int Position { 33 | get { return position; } 34 | } 35 | 36 | public ReflectionNameParseException(int position) 37 | { 38 | this.position = position; 39 | } 40 | 41 | public ReflectionNameParseException(int position, string message) : base(message) 42 | { 43 | this.position = position; 44 | } 45 | 46 | public ReflectionNameParseException(int position, string message, Exception innerException) : base(message, innerException) 47 | { 48 | this.position = position; 49 | } 50 | 51 | // This constructor is needed for serialization. 52 | protected ReflectionNameParseException(SerializationInfo info, StreamingContext context) : base(info, context) 53 | { 54 | position = info.GetInt32("position"); 55 | } 56 | 57 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 58 | { 59 | base.GetObjectData(info, context); 60 | info.AddValue("position", position); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/CacheManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Concurrent; 21 | 22 | namespace ICSharpCode.Decompiler.Util 23 | { 24 | /// 25 | /// Allows caching values for a specific compilation. 26 | /// A CacheManager consists of a for shared instances (shared among all threads working with that resolve context). 27 | /// 28 | /// This class is thread-safe 29 | public sealed class CacheManager 30 | { 31 | readonly ConcurrentDictionary sharedDict = new ConcurrentDictionary(ReferenceComparer.Instance); 32 | // There used to be a thread-local dictionary here, but I removed it as it was causing memory 33 | // leaks in some use cases. 34 | 35 | public object GetShared(object key) 36 | { 37 | object value; 38 | sharedDict.TryGetValue(key, out value); 39 | return value; 40 | } 41 | 42 | public object GetOrAddShared(object key, Func valueFactory) 43 | { 44 | return sharedDict.GetOrAdd(key, valueFactory); 45 | } 46 | 47 | public object GetOrAddShared(object key, object value) 48 | { 49 | return sharedDict.GetOrAdd(key, value); 50 | } 51 | 52 | public void SetShared(object key, object value) 53 | { 54 | sharedDict[key] = value; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/CallbackOnDispose.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Threading; 21 | 22 | namespace ICSharpCode.Decompiler.Util 23 | { 24 | /// 25 | /// Invokes an action when it is disposed. 26 | /// 27 | /// 28 | /// This class ensures the callback is invoked at most once, 29 | /// even when Dispose is called on multiple threads. 30 | /// 31 | public sealed class CallbackOnDispose : IDisposable 32 | { 33 | Action action; 34 | 35 | public CallbackOnDispose(Action action) 36 | { 37 | if (action == null) 38 | throw new ArgumentNullException(nameof(action)); 39 | this.action = action; 40 | } 41 | 42 | public void Dispose() 43 | { 44 | var a = Interlocked.Exchange(ref action, null); 45 | if (a != null) 46 | { 47 | a(); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace ICSharpCode.Decompiler.Util 22 | { 23 | /// 24 | /// Contains extension methods for internal use within the decompiler. 25 | /// 26 | static class ExtensionMethods 27 | { 28 | public static Predicate And(this Predicate filter1, Predicate filter2) 29 | { 30 | if (filter1 == null) 31 | return filter2; 32 | if (filter2 == null) 33 | return filter1; 34 | return m => filter1(m) && filter2(m); 35 | } 36 | 37 | public static void Swap(ref T a, ref T b) 38 | { 39 | var tmp = a; 40 | a = b; 41 | b = tmp; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/LazyInit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Threading; 20 | 21 | namespace ICSharpCode.Decompiler.Util 22 | { 23 | public static class LazyInit 24 | { 25 | public static T VolatileRead(ref T location) where T : class 26 | { 27 | return Volatile.Read(ref location); 28 | } 29 | 30 | /// 31 | /// Atomically performs the following operation: 32 | /// - If target is null: stores newValue in target and returns newValue. 33 | /// - If target is not null: returns target. 34 | /// 35 | public static T GetOrSet(ref T target, T newValue) where T : class 36 | { 37 | var oldValue = Interlocked.CompareExchange(ref target, newValue, null); 38 | return oldValue ?? newValue; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/Platform.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace ICSharpCode.Decompiler.Util 22 | { 23 | /// 24 | /// Platform-specific code. 25 | /// 26 | public static class Platform 27 | { 28 | public static StringComparer FileNameComparer { 29 | get { 30 | switch (Environment.OSVersion.Platform) 31 | { 32 | case PlatformID.Unix: 33 | case PlatformID.MacOSX: 34 | return StringComparer.Ordinal; 35 | default: 36 | return StringComparer.OrdinalIgnoreCase; 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/ReferenceComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.Runtime.CompilerServices; 21 | 22 | namespace ICSharpCode.Decompiler.Util 23 | { 24 | public sealed class ReferenceComparer : IEqualityComparer 25 | { 26 | public readonly static ReferenceComparer Instance = new ReferenceComparer(); 27 | 28 | public new bool Equals(object x, object y) 29 | { 30 | return x == y; 31 | } 32 | 33 | public int GetHashCode(object obj) 34 | { 35 | return RuntimeHelpers.GetHashCode(obj); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/ICSharpCode.Decompiler/Util/UnionFind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | namespace ICSharpCode.Decompiler.Util 22 | { 23 | /// 24 | /// Union-Find data structure. 25 | /// 26 | public class UnionFind 27 | { 28 | Dictionary mapping; 29 | 30 | class Node 31 | { 32 | public int rank; 33 | public Node parent; 34 | public T value; 35 | } 36 | 37 | public UnionFind() 38 | { 39 | mapping = new Dictionary(); 40 | } 41 | 42 | Node GetNode(T element) 43 | { 44 | Node node; 45 | if (!mapping.TryGetValue(element, out node)) 46 | { 47 | node = new Node { 48 | value = element, 49 | rank = 0 50 | }; 51 | node.parent = node; 52 | mapping.Add(element, node); 53 | } 54 | return node; 55 | } 56 | 57 | public T Find(T element) 58 | { 59 | return FindRoot(GetNode(element)).value; 60 | } 61 | 62 | Node FindRoot(Node node) 63 | { 64 | if (node.parent != node) 65 | node.parent = FindRoot(node.parent); 66 | return node.parent; 67 | } 68 | 69 | public void Merge(T a, T b) 70 | { 71 | var rootA = FindRoot(GetNode(a)); 72 | var rootB = FindRoot(GetNode(b)); 73 | if (rootA == rootB) 74 | return; 75 | if (rootA.rank < rootB.rank) 76 | rootA.parent = rootB; 77 | else if (rootA.rank > rootB.rank) 78 | rootB.parent = rootA; 79 | else 80 | { 81 | rootB.parent = rootA; 82 | rootA.rank++; 83 | } 84 | } 85 | } 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/CommentGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using BenchmarkDotNet.Attributes; 7 | using BenchmarkDotNet.Jobs; 8 | 9 | using Pharmacist.Core.Generation; 10 | 11 | namespace Pharmacist.Benchmarks 12 | { 13 | [SimpleJob(RuntimeMoniker.Net461)] 14 | [SimpleJob(RuntimeMoniker.NetCoreApp31)] 15 | [MemoryDiagnoser] 16 | [MarkdownExporterAttribute.GitHub] 17 | public class CommentGenerator 18 | { 19 | private static readonly string[] _testValues = { "This is a test {0}.", "Test2 this is a test {0}" }; 20 | private static readonly string[] _testValuesTypes = { "System.Blah1", "System.Blah2" }; 21 | 22 | /// 23 | /// A benchmark which tests the method. 24 | /// 25 | [Benchmark] 26 | public void GenerateSummarySeeAlsoCommentBenchmark() 27 | { 28 | for (var i = 0; i < _testValues.Length * 5; ++i) 29 | { 30 | var currentIndex = i % _testValues.Length; 31 | var testValue = _testValues[currentIndex]; 32 | var testValueType = _testValuesTypes[currentIndex]; 33 | var syntax = XmlSyntaxFactory.GenerateSummarySeeAlsoComment(testValue, testValueType); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/Directory.build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/NuGetHelperBenchmarks.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Threading.Tasks; 3 | 4 | using BenchmarkDotNet.Attributes; 5 | using BenchmarkDotNet.Jobs; 6 | 7 | using NuGet.Frameworks; 8 | using NuGet.Packaging.Core; 9 | using NuGet.Versioning; 10 | 11 | using Pharmacist.Core.NuGet; 12 | 13 | namespace Pharmacist.Benchmarks 14 | { 15 | [SimpleJob(RuntimeMoniker.Net461)] 16 | [SimpleJob(RuntimeMoniker.NetCoreApp31)] 17 | [MemoryDiagnoser] 18 | [MarkdownExporterAttribute.GitHub] 19 | public class NuGetTaskGeneratorBenchmarks 20 | { 21 | private static readonly string _packageDirectory = Path.Combine(Path.GetTempPath(), "Pharmacist.Benchamarks"); 22 | 23 | [IterationSetup] 24 | public void IterationSetup() 25 | { 26 | try 27 | { 28 | Directory.Delete(_packageDirectory); 29 | } 30 | catch 31 | { 32 | } 33 | } 34 | 35 | [Benchmark] 36 | public async Task MultipleDirectoryCase() 37 | { 38 | // NetCore contains multiple directories that match. 39 | var package = new[] { new PackageIdentity("Microsoft.NETCore.App", new NuGetVersion("2.0.0")) }; 40 | var frameworks = new[] { FrameworkConstants.CommonFrameworks.NetCoreApp20 }; 41 | 42 | var result = (await NuGetPackageHelper 43 | .DownloadPackageFilesAndFolder(package, frameworks, packageOutputDirectory: _packageDirectory) 44 | .ConfigureAwait(false)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/Pharmacist.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | false 6 | net472;net6.0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/PlatformGeneratorBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Threading.Tasks; 7 | 8 | using BenchmarkDotNet.Attributes; 9 | using BenchmarkDotNet.Jobs; 10 | 11 | using Pharmacist.Core; 12 | 13 | namespace Pharmacist.Benchmarks 14 | { 15 | /// 16 | /// Benchmarks for the NavigationStack and the RoutingState objects. 17 | /// 18 | [SimpleJob(RuntimeMoniker.Net461)] 19 | [SimpleJob(RuntimeMoniker.NetCoreApp31)] 20 | [MemoryDiagnoser] 21 | [MarkdownExporterAttribute.GitHub] 22 | public class NavigationStackBenchmark 23 | { 24 | private static string _referenceAssembliesLocation = PlatformHelper.IsRunningOnMono() ? 25 | @"/Library⁩/Frameworks⁩/Libraries/⁨mono⁩" : 26 | @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework"; 27 | 28 | /// 29 | /// Benchmark for when navigating to a new view model. 30 | /// 31 | [Benchmark] 32 | public Task Navigate() 33 | { 34 | return Task.CompletedTask; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Pharmacist.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using BenchmarkDotNet.Running; 7 | 8 | namespace Pharmacist.Benchmarks 9 | { 10 | /// 11 | /// Class which hosts the main entry point into the application. 12 | /// 13 | public static class Program 14 | { 15 | /// 16 | /// The main entry point into the benchmarking application. 17 | /// 18 | /// Arguments from the command line. 19 | public static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Pharmacist.Common/Pharmacist.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net6.0;net7.0 5 | $(TargetFrameworks);net472 6 | Pharmacist.Common 7 | enable 8 | latest 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Pharmacist.Common/SingleAwaitSubject.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Reactive.Linq; 8 | using System.Reactive.Subjects; 9 | 10 | namespace Pharmacist.Common 11 | { 12 | /// 13 | /// A subject which will have a single awaiter. 14 | /// 15 | /// The type of signals given by the subject. 16 | public sealed class SingleAwaitSubject : ISubject, IDisposable 17 | { 18 | private readonly Subject _inner = new(); 19 | 20 | /// 21 | /// Gets the awaiter based on the first item in the collection. 22 | /// 23 | /// The async subject awaiter. 24 | public AsyncSubject GetAwaiter() 25 | { 26 | return _inner.Take(1).GetAwaiter(); 27 | } 28 | 29 | /// 30 | public void OnNext(T value) 31 | { 32 | _inner.OnNext(value); 33 | } 34 | 35 | /// 36 | public void OnError(Exception error) 37 | { 38 | _inner.OnError(error); 39 | } 40 | 41 | /// 42 | public void OnCompleted() 43 | { 44 | _inner.OnCompleted(); 45 | } 46 | 47 | /// 48 | public IDisposable Subscribe(IObserver observer) 49 | { 50 | return _inner.Subscribe(observer); 51 | } 52 | 53 | /// 54 | public void Dispose() 55 | { 56 | _inner?.Dispose(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/CommandOptions/CommandLineOptionsBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using CommandLine; 7 | 8 | namespace Pharmacist.Console.CommandOptions 9 | { 10 | /// 11 | /// A base class for commonly shared options. 12 | /// 13 | public abstract class CommandLineOptionsBase 14 | { 15 | /// 16 | /// Gets or sets the path where to output the contents. 17 | /// 18 | [Option('o', "output-path", Required = true, HelpText = "The directory path where to output the contents.")] 19 | public string? OutputPath { get; set; } 20 | 21 | /// 22 | /// Gets or sets the output file prefix. 23 | /// 24 | [Option("output-prefix", Required = true, HelpText = "Specify a prefix for the output file based on the platforms selected. Each platform output file will contain this prefix.")] 25 | public string? OutputPrefix { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/CommandOptions/CustomAssembliesCommandLineOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | using CommandLine; 9 | 10 | namespace Pharmacist.Console.CommandOptions 11 | { 12 | /// 13 | /// A options class that represent when the user wants to generate from their own custom list of assemblies and search directories. 14 | /// 15 | [Verb("generate-custom", HelpText = "Generate from own specified assembly paths and search directories.")] 16 | public class CustomAssembliesCommandLineOptions : CommandLineOptionsBase 17 | { 18 | /// 19 | /// Gets or sets the reference assemblies. 20 | /// 21 | [Option('s', "search-directories", Required = true, HelpText = "Specify a search directories where to search for additional support libraries.")] 22 | public IEnumerable? SearchDirectories { get; set; } 23 | 24 | /// 25 | /// Gets or sets the assemblies. 26 | /// Manual generation using the specified assemblies. Use with --platform=NONE. 27 | /// 28 | [Option('a', "assemblies", Required = true, HelpText = "List of assemblies to process.")] 29 | public IEnumerable? Assemblies { get; set; } 30 | 31 | /// 32 | /// Gets or sets the reference assemblies. 33 | /// 34 | [Option('t', "target-framework", Required = true, HelpText = "Specify the Target framework to extract for.")] 35 | public string? TargetFramework { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/CommandOptions/NugetCommandLineOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using CommandLine; 7 | 8 | namespace Pharmacist.Console.CommandOptions 9 | { 10 | /// 11 | /// Command line options for working in a NuGet package mode. 12 | /// 13 | [Verb("generate-nuget", HelpText = "Generate from a specified NuGet package.")] 14 | public class NugetCommandLineOptions : CommandLineOptionsBase 15 | { 16 | /// 17 | /// Gets or sets the platform. 18 | /// 19 | [Option('p', "package", Required = true, HelpText = "The name of the NuGet package.")] 20 | public string? NugetPackageName { get; set; } 21 | 22 | /// 23 | /// Gets or sets the reference assemblies. 24 | /// 25 | [Option('v', "version", Required = true, HelpText = "Specify the NuGet version number.")] 26 | public string? NugetVersion { get; set; } 27 | 28 | /// 29 | /// Gets or sets the reference assemblies. 30 | /// 31 | [Option('t', "target-framework", Required = true, HelpText = "Specify the Target framework to extract for.")] 32 | public string? TargetFramework { get; set; } 33 | 34 | /// 35 | /// Gets or sets the package folder. If not set a random folder will be used. 36 | /// 37 | [Option("package-folder", HelpText = "Optional folder where to place NuGet packages for processing, otherwise random temp folder will be used.")] 38 | public string? PackageFolder { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/CommandOptions/PlatformCommandLineOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | using CommandLine; 9 | 10 | namespace Pharmacist.Console.CommandOptions 11 | { 12 | /// 13 | /// Command line options for the platform based generation. 14 | /// 15 | [Verb("generate-platform", HelpText = "Generate from a predetermined platform.")] 16 | public class PlatformCommandLineOptions : CommandLineOptionsBase 17 | { 18 | /// 19 | /// Gets or sets the target framework. 20 | /// 21 | [Option('t', "target-frameworks", Required = true, HelpText = "Specify the target framework monikiers.", Separator = ',')] 22 | public IEnumerable? TargetFrameworks { get; set; } 23 | 24 | /// 25 | /// Gets or sets a value indicating whether to use WPF. 26 | /// 27 | [Option("is-wpf", Required = false, HelpText = "Specify if WPF libraries should be used.")] 28 | public bool IsWpf { get; set; } 29 | 30 | /// 31 | /// Gets or sets a value indicating whether to use WinForms. 32 | /// 33 | [Option("is-winforms", Required = false, HelpText = "Specify if WinForms libraries should be used.")] 34 | public bool IsWinForms { get; set; } 35 | 36 | /// 37 | /// Gets or sets the reference assemblies. 38 | /// 39 | [Option('r', "reference", Required = false, HelpText = "Specify a Reference Assemblies location to override the default.")] 40 | public string? ReferenceAssemblies { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/ExitCode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | namespace Pharmacist.Console 7 | { 8 | /// 9 | /// The exit/return code (aka %ERRORLEVEL%) on application exit. 10 | /// 11 | public enum ExitCode 12 | { 13 | /// 14 | /// Success. 15 | /// 16 | Success = 0, 17 | 18 | /// 19 | /// Error. 20 | /// 21 | Error = 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/Pharmacist.Console.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | net6.0 5 | Pharmacist 6 | latest 7 | true 8 | enable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Pharmacist.Console/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "EventBuilder.Console": { 4 | "commandName": "Project" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /src/Pharmacist.Core/Comparers/AssemblyReferenceNameComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using ICSharpCode.Decompiler.Metadata; 9 | 10 | namespace Pharmacist.Core.Comparers 11 | { 12 | internal class AssemblyReferenceNameComparer : IEqualityComparer 13 | { 14 | public static AssemblyReferenceNameComparer Default { get; } = new(); 15 | 16 | /// 17 | public bool Equals(IAssemblyReference? x, IAssemblyReference? y) 18 | { 19 | if (x == null && y == null) 20 | { 21 | return true; 22 | } 23 | 24 | if (x == null || y == null) 25 | { 26 | return false; 27 | } 28 | 29 | return StringComparer.InvariantCulture.Equals(x.FullName, y.FullName); 30 | } 31 | 32 | /// 33 | public int GetHashCode(IAssemblyReference obj) 34 | { 35 | return StringComparer.InvariantCulture.GetHashCode(obj.FullName); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Comparers/NuGetFrameworkInRangeComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | using NuGet.Frameworks; 10 | 11 | namespace Pharmacist.Core.Comparers 12 | { 13 | internal class NuGetFrameworkInRangeComparer : IComparer, IEqualityComparer 14 | { 15 | public static NuGetFrameworkInRangeComparer Default { get; } = new(); 16 | 17 | /// 18 | public bool Equals(NuGetFramework? x, NuGetFramework? y) 19 | { 20 | if (x == null && y == null) 21 | { 22 | return true; 23 | } 24 | 25 | if (x == null || y == null) 26 | { 27 | return false; 28 | } 29 | 30 | if (ReferenceEquals(x, y)) 31 | { 32 | return true; 33 | } 34 | 35 | if (!NuGetFramework.FrameworkNameComparer.Equals(x, y)) 36 | { 37 | return false; 38 | } 39 | 40 | return x.Version >= y.Version; 41 | } 42 | 43 | /// 44 | public int GetHashCode(NuGetFramework obj) 45 | { 46 | return NuGetFramework.FrameworkNameComparer.GetHashCode(obj); 47 | } 48 | 49 | /// 50 | public int Compare(NuGetFramework? x, NuGetFramework? y) 51 | { 52 | switch (x) 53 | { 54 | case null when y is null: 55 | return 0; 56 | case null: 57 | return 1; 58 | } 59 | 60 | if (y is null) 61 | { 62 | return -1; 63 | } 64 | 65 | var result = StringComparer.OrdinalIgnoreCase.Compare(x.Framework, y.Framework); 66 | 67 | return result != 0 ? result : x.Version.CompareTo(y.Version); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Comparers/PackageIdentityNameComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | using NuGet.Packaging.Core; 10 | 11 | namespace Pharmacist.Core.Comparers 12 | { 13 | internal class PackageIdentityNameComparer : IEqualityComparer 14 | { 15 | public static PackageIdentityNameComparer Default { get; } = new(); 16 | 17 | /// 18 | public bool Equals(PackageIdentity? x, PackageIdentity? y) 19 | { 20 | if (x == null && y == null) 21 | { 22 | return true; 23 | } 24 | 25 | if (x == null || y == null) 26 | { 27 | return false; 28 | } 29 | 30 | return ReferenceEquals(x, y) || StringComparer.OrdinalIgnoreCase.Equals(x.Id, y.Id); 31 | } 32 | 33 | /// 34 | public int GetHashCode(PackageIdentity obj) 35 | { 36 | return StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Id); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/IExtractor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using Pharmacist.Core.Groups; 7 | 8 | namespace Pharmacist.Core.Extractors 9 | { 10 | /// 11 | /// Extracts information from a platform, assembly or nuget package. 12 | /// 13 | public interface IExtractor 14 | { 15 | /// 16 | /// Gets the input for the generators and resolvers. 17 | /// 18 | InputAssembliesGroup? Input { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/NuGetExtractor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | 9 | using NuGet.Frameworks; 10 | using NuGet.LibraryModel; 11 | using NuGet.Packaging.Core; 12 | 13 | using Pharmacist.Core.Groups; 14 | using Pharmacist.Core.NuGet; 15 | 16 | namespace Pharmacist.Core.Extractors 17 | { 18 | /// 19 | /// A extractor which will extract assembly information from a NuGet package. 20 | /// 21 | public class NuGetExtractor : IExtractor 22 | { 23 | /// 24 | public InputAssembliesGroup? Input { get; protected set; } 25 | 26 | /// 27 | /// Extracts the data using the specified target framework. 28 | /// 29 | /// The target framework to extract in order of priority. 30 | /// The packages to extract the information from. 31 | /// Directory for the packages, if null a random path in the temp folder will be used. 32 | /// A task to monitor the progress. 33 | public async Task Extract(IReadOnlyCollection targetFrameworks, IReadOnlyCollection packages, string? packageOutputDirectory) 34 | { 35 | Input = await NuGetPackageHelper.DownloadPackageFilesAndFolder(packages, targetFrameworks, packageOutputDirectory: packageOutputDirectory).ConfigureAwait(false); 36 | } 37 | 38 | /// 39 | /// Extracts the data using the specified target framework. 40 | /// 41 | /// The target framework to extract in order of priority. 42 | /// The packages to extract the information from. 43 | /// Directory for the packages, if null a random path in the temp folder will be used. 44 | /// A task to monitor the progress. 45 | public async Task Extract(IReadOnlyCollection targetFrameworks, IReadOnlyCollection packages, string? packageOutputDirectory) 46 | { 47 | Input = await NuGetPackageHelper.DownloadPackageFilesAndFolder(packages, targetFrameworks, packageOutputDirectory: packageOutputDirectory).ConfigureAwait(false); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/Android.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | 11 | using NuGet.Frameworks; 12 | 13 | using Pharmacist.Core.NuGet; 14 | using Pharmacist.Core.Utilities; 15 | 16 | namespace Pharmacist.Core.Extractors.PlatformExtractors 17 | { 18 | /// 19 | /// 20 | /// The Android platform. 21 | /// 22 | /// 23 | public class Android : BasePlatform 24 | { 25 | /// 26 | public override bool CanExtract(NuGetFramework[] frameworks) 27 | { 28 | if (frameworks == null) 29 | { 30 | throw new ArgumentNullException(nameof(frameworks)); 31 | } 32 | 33 | var framework = frameworks[0]; 34 | 35 | return framework.Framework.StartsWith("MonoAndroid", StringComparison.InvariantCultureIgnoreCase); 36 | } 37 | 38 | /// 39 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 40 | { 41 | if (frameworks == null) 42 | { 43 | throw new ArgumentNullException(nameof(frameworks)); 44 | } 45 | 46 | var framework = frameworks[0]; 47 | 48 | Input.IncludeGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(framework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet).Where(x => Path.GetFileName(x).Equals("Mono.Android.dll", StringComparison.InvariantCultureIgnoreCase))); 49 | return Task.CompletedTask; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/BasePlatform.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Threading.Tasks; 7 | 8 | using NuGet.Frameworks; 9 | 10 | using Pharmacist.Core.Groups; 11 | 12 | namespace Pharmacist.Core.Extractors.PlatformExtractors 13 | { 14 | /// 15 | /// Base platform. 16 | /// 17 | public abstract class BasePlatform : IPlatformExtractor 18 | { 19 | /// 20 | public InputAssembliesGroup Input { get; } = new(); 21 | 22 | /// 23 | public abstract bool CanExtract(NuGetFramework[] frameworks); 24 | 25 | /// 26 | public abstract Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/IPlatformExtractor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Threading.Tasks; 7 | 8 | using NuGet.Frameworks; 9 | 10 | namespace Pharmacist.Core.Extractors.PlatformExtractors 11 | { 12 | /// 13 | /// Interface representing a platform assemblies and events. 14 | /// 15 | public interface IPlatformExtractor : IExtractor 16 | { 17 | /// 18 | /// If the extractor can extract for the framework. 19 | /// 20 | /// The framework to check. 21 | /// If the extraction works. 22 | bool CanExtract(NuGetFramework[] frameworks); 23 | 24 | /// 25 | /// Extract details about the platform. 26 | /// 27 | /// The frameworks to extract for. 28 | /// The location for reference assemblies if needed. 29 | /// A task to monitor the progress. 30 | Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/Mac.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | using NuGet.Frameworks; 13 | 14 | using Pharmacist.Core.NuGet; 15 | using Pharmacist.Core.Utilities; 16 | 17 | namespace Pharmacist.Core.Extractors.PlatformExtractors 18 | { 19 | /// 20 | /// Mac platform assemblies and events. 21 | /// 22 | public class Mac : BasePlatform 23 | { 24 | /// 25 | public override bool CanExtract(NuGetFramework[] frameworks) 26 | { 27 | if (frameworks == null) 28 | { 29 | throw new ArgumentNullException(nameof(frameworks)); 30 | } 31 | 32 | var framework = frameworks[0]; 33 | 34 | return framework.Framework.StartsWith("Xamarin.Mac", StringComparison.InvariantCultureIgnoreCase); 35 | } 36 | 37 | /// 38 | [SuppressMessage("Usage", "CA2249:Consider using 'string.Contains' instead of 'string.IndexOf'", Justification = "Not supported on all platforms.")] 39 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 40 | { 41 | if (frameworks == null) 42 | { 43 | throw new ArgumentNullException(nameof(frameworks)); 44 | } 45 | 46 | var framework = frameworks[0]; 47 | 48 | Input.IncludeGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(framework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet).Where(x => Path.GetFileName(x).IndexOf("Xamarin.Mac", StringComparison.InvariantCultureIgnoreCase) >= 0)); 49 | 50 | return Task.CompletedTask; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/UWP.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Threading.Tasks; 8 | 9 | using NuGet.Frameworks; 10 | 11 | using Pharmacist.Core.Utilities; 12 | 13 | namespace Pharmacist.Core.Extractors.PlatformExtractors 14 | { 15 | /// 16 | /// UWP platform assemblies and events. 17 | /// 18 | public class UWP : BasePlatform 19 | { 20 | /// 21 | public override bool CanExtract(NuGetFramework[] frameworks) 22 | { 23 | if (frameworks == null) 24 | { 25 | throw new ArgumentNullException(nameof(frameworks)); 26 | } 27 | 28 | var framework = frameworks[0]; 29 | 30 | return framework.Framework.StartsWith("uap", StringComparison.InvariantCultureIgnoreCase); 31 | } 32 | 33 | /// 34 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 35 | { 36 | if (frameworks == null) 37 | { 38 | throw new ArgumentNullException(nameof(frameworks)); 39 | } 40 | 41 | var framework = frameworks[0]; 42 | 43 | if (PlatformHelper.IsRunningOnMono()) 44 | { 45 | throw new NotSupportedException("Building events for UWP on Mac is not implemented yet."); 46 | } 47 | 48 | var metadataFile = AssemblyHelpers.FindUnionMetadataFile("Windows", framework.Version); 49 | 50 | if (metadataFile != null && !string.IsNullOrWhiteSpace(metadataFile)) 51 | { 52 | Input.IncludeGroup.AddFiles(new[] { metadataFile }); 53 | } 54 | 55 | return Task.CompletedTask; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/WPF.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | using NuGet.Frameworks; 10 | 11 | namespace Pharmacist.Core.Extractors.PlatformExtractors 12 | { 13 | /// 14 | /// WPF platform assemblies and events. 15 | /// 16 | internal class WPF : NetExtractorBase 17 | { 18 | public WPF(string? filePath) 19 | : base(filePath) 20 | { 21 | } 22 | 23 | /// 24 | protected override HashSet WantedFileNames { get; } = new(StringComparer.CurrentCultureIgnoreCase) 25 | { 26 | "WindowsBase.dll", 27 | "PresentationCore.dll", 28 | "PresentationFramework.dll" 29 | }; 30 | 31 | public override bool CanExtract(NuGetFramework[] frameworks) 32 | { 33 | if (frameworks == null) 34 | { 35 | throw new ArgumentNullException(nameof(frameworks)); 36 | } 37 | 38 | var framework = frameworks[0]; 39 | 40 | if (framework.Framework.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase)) 41 | { 42 | return true; 43 | } 44 | 45 | if (framework.Framework.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) 46 | && framework.Version > new Version(3, 1)) 47 | { 48 | return true; 49 | } 50 | 51 | return framework.Framework.Equals(FrameworkConstants.CommonFrameworks.Net50.Framework); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/WatchOs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | using NuGet.Frameworks; 13 | 14 | using Pharmacist.Core.NuGet; 15 | using Pharmacist.Core.Utilities; 16 | 17 | namespace Pharmacist.Core.Extractors.PlatformExtractors 18 | { 19 | /// 20 | /// WatchOS platform assemblies and events. 21 | /// 22 | public class WatchOs : BasePlatform 23 | { 24 | /// 25 | public override bool CanExtract(NuGetFramework[] frameworks) 26 | { 27 | if (frameworks == null) 28 | { 29 | throw new ArgumentNullException(nameof(frameworks)); 30 | } 31 | 32 | var framework = frameworks[0]; 33 | 34 | return framework.Framework.StartsWith("Xamarin.WatchOS", StringComparison.InvariantCultureIgnoreCase); 35 | } 36 | 37 | /// 38 | [SuppressMessage( 39 | "Usage", 40 | "CA2249:Consider using 'string.Contains' instead of 'string.IndexOf'", 41 | Justification = "Not supported on all platforms.")] 42 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 43 | { 44 | if (frameworks == null) 45 | { 46 | throw new ArgumentNullException(nameof(frameworks)); 47 | } 48 | 49 | var framework = frameworks[0]; 50 | 51 | Input.IncludeGroup.AddFiles( 52 | FileSystemHelpers.GetFilesWithinSubdirectories(framework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet).Where( 53 | x => Path.GetFileName(x).IndexOf("Xamarin.WatchOS", StringComparison.InvariantCultureIgnoreCase) >= 0)); 54 | return Task.CompletedTask; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/Winforms.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | using NuGet.Frameworks; 10 | 11 | namespace Pharmacist.Core.Extractors.PlatformExtractors 12 | { 13 | /// 14 | /// Win Forms platform assemblies and events. 15 | /// 16 | internal class Winforms : NetExtractorBase 17 | { 18 | public Winforms(string? filePath) 19 | : base(filePath) 20 | { 21 | } 22 | 23 | /// 24 | protected override HashSet WantedFileNames { get; } = new(StringComparer.CurrentCultureIgnoreCase) 25 | { 26 | "System.DirectoryServices.dll", 27 | "System.Windows.Forms.dll", 28 | "System.Drawing.dll" 29 | }; 30 | 31 | public override bool CanExtract(NuGetFramework[] frameworks) 32 | { 33 | if (frameworks == null) 34 | { 35 | throw new ArgumentNullException(nameof(frameworks)); 36 | } 37 | 38 | var framework = frameworks[0]; 39 | 40 | if (framework.Framework.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase)) 41 | { 42 | return true; 43 | } 44 | 45 | if (framework.Framework.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) 46 | && framework.Version > new Version(3, 1)) 47 | { 48 | return true; 49 | } 50 | 51 | return framework.Framework.Equals(FrameworkConstants.CommonFrameworks.Net50.Framework); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/iOS.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | using NuGet.Frameworks; 13 | 14 | using Pharmacist.Core.NuGet; 15 | using Pharmacist.Core.Utilities; 16 | 17 | namespace Pharmacist.Core.Extractors.PlatformExtractors 18 | { 19 | /// 20 | /// 21 | /// iOS platform assemblies and events. 22 | /// 23 | [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "iOS special naming scheme.")] 24 | public class iOS : BasePlatform 25 | { 26 | /// 27 | public override bool CanExtract(NuGetFramework[] frameworks) 28 | { 29 | if (frameworks == null) 30 | { 31 | throw new ArgumentNullException(nameof(frameworks)); 32 | } 33 | 34 | var framework = frameworks[0]; 35 | 36 | return framework.Framework.StartsWith("Xamarin.iOS", StringComparison.InvariantCultureIgnoreCase); 37 | } 38 | 39 | /// 40 | [SuppressMessage("Usage", "CA2249:Consider using 'string.Contains' instead of 'string.IndexOf'", Justification = "Not supported on all platforms.")] 41 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 42 | { 43 | if (frameworks == null) 44 | { 45 | throw new ArgumentNullException(nameof(frameworks)); 46 | } 47 | 48 | var framework = frameworks[0]; 49 | 50 | Input.IncludeGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(framework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet).Where(x => Path.GetFileName(x).IndexOf("Xamarin.iOS", StringComparison.InvariantCultureIgnoreCase) >= 0)); 51 | return Task.CompletedTask; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Extractors/PlatformExtractors/tvOS.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | using NuGet.Frameworks; 13 | 14 | using Pharmacist.Core.NuGet; 15 | using Pharmacist.Core.Utilities; 16 | 17 | namespace Pharmacist.Core.Extractors.PlatformExtractors 18 | { 19 | /// 20 | /// TV OS platform assemblies and events. 21 | /// 22 | public class TVOS : BasePlatform 23 | { 24 | /// 25 | public override bool CanExtract(NuGetFramework[] frameworks) 26 | { 27 | if (frameworks == null) 28 | { 29 | throw new ArgumentNullException(nameof(frameworks)); 30 | } 31 | 32 | var framework = frameworks[0]; 33 | 34 | return framework.Framework.StartsWith("Xamarin.TVOS", StringComparison.InvariantCultureIgnoreCase); 35 | } 36 | 37 | /// 38 | [SuppressMessage("Usage", "CA2249:Consider using 'string.Contains' instead of 'string.IndexOf'", Justification = "Not supported on all platforms.")] 39 | public override Task Extract(NuGetFramework[] frameworks, string referenceAssembliesLocation) 40 | { 41 | if (frameworks == null) 42 | { 43 | throw new ArgumentNullException(nameof(frameworks)); 44 | } 45 | 46 | var framework = frameworks[0]; 47 | 48 | Input.IncludeGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(framework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet).Where(x => Path.GetFileName(x).IndexOf("Xamarin.TVOS", StringComparison.InvariantCultureIgnoreCase) >= 0)); 49 | return Task.CompletedTask; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/Compilation/KnownTypeCache.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using ICSharpCode.Decompiler.TypeSystem; 7 | using ICSharpCode.Decompiler.TypeSystem.Implementation; 8 | using ICSharpCode.Decompiler.Util; 9 | 10 | namespace Pharmacist.Core.Generation.Compilation 11 | { 12 | /// 13 | /// Cache for KnownTypeReferences. 14 | /// Based on https://github.com/icsharpcode/ILSpy/blob/master/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs 15 | /// and the ILSpy project. 16 | /// 17 | internal sealed class KnownTypeCache 18 | { 19 | private readonly ICompilation _compilation; 20 | private readonly IType[] _knownTypes = new IType[(int)KnownTypeCode.MemoryOfT + 1]; 21 | 22 | public KnownTypeCache(ICompilation compilation) 23 | { 24 | _compilation = compilation; 25 | } 26 | 27 | public IType FindType(KnownTypeCode typeCode) 28 | { 29 | var type = LazyInit.VolatileRead(ref _knownTypes[(int)typeCode]); 30 | return type ?? LazyInit.GetOrSet(ref _knownTypes[(int)typeCode], SearchType(typeCode)); 31 | } 32 | 33 | private IType SearchType(KnownTypeCode typeCode) 34 | { 35 | var typeRef = KnownTypeReference.Get(typeCode); 36 | if (typeRef == null) 37 | { 38 | return SpecialType.UnknownType; 39 | } 40 | 41 | var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); 42 | foreach (var asm in _compilation.Modules) 43 | { 44 | var typeDef = asm.GetTypeDefinition(typeName); 45 | if (typeDef != null) 46 | { 47 | return typeDef; 48 | } 49 | } 50 | 51 | return new UnknownType(typeName); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/EventNameComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using ICSharpCode.Decompiler.TypeSystem; 9 | 10 | namespace Pharmacist.Core.Generation 11 | { 12 | internal class EventNameComparer : IComparer, IEqualityComparer 13 | { 14 | public static EventNameComparer Default { get; } = new(); 15 | 16 | public int Compare(IEvent? x, IEvent? y) 17 | { 18 | switch (x) 19 | { 20 | case null when y == null: 21 | return 0; 22 | case null: 23 | return 1; 24 | } 25 | 26 | if (y == null) 27 | { 28 | return -1; 29 | } 30 | 31 | return ReferenceEquals(x, y) ? 0 : string.Compare(x.Name, y.Name, StringComparison.InvariantCulture); 32 | } 33 | 34 | public bool Equals(IEvent? x, IEvent? y) 35 | { 36 | if (x == null && y == null) 37 | { 38 | return true; 39 | } 40 | 41 | if (x == null || y == null) 42 | { 43 | return false; 44 | } 45 | 46 | return ReferenceEquals(x, y) || string.Equals(x.Name, y.Name, StringComparison.InvariantCulture); 47 | } 48 | 49 | public int GetHashCode(IEvent obj) 50 | { 51 | return obj.Name.GetHashCode(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/Generators/IEventGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | using ICSharpCode.Decompiler.TypeSystem; 9 | 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | 12 | namespace Pharmacist.Core.Generation.Generators 13 | { 14 | /// 15 | /// Generates based on events in the base code. 16 | /// 17 | internal interface IEventGenerator 18 | { 19 | /// 20 | /// Generates a compilation unit based on generating event observable wrappers. 21 | /// 22 | /// The values to generate for. 23 | /// The new compilation unit. 24 | IEnumerable Generate(IEnumerable<(ITypeDefinition TypeDefinition, ITypeDefinition? BaseDefinition, IEnumerable Events)> values); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/Resolvers/EventNamespaceResolverBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | using ICSharpCode.Decompiler.TypeSystem; 10 | 11 | using Microsoft.CodeAnalysis.CSharp.Syntax; 12 | 13 | using Pharmacist.Core.Generation.Generators; 14 | 15 | namespace Pharmacist.Core.Generation.Resolvers 16 | { 17 | /// 18 | /// A namespace resolver that extracts event information. 19 | /// 20 | internal abstract class EventNamespaceResolverBase : INamespaceResolver 21 | { 22 | /// 23 | public IEnumerable Create(ICompilation compilation) 24 | { 25 | var typesAndEvents = GetValidEventDetails(compilation); 26 | 27 | return GetEventGenerator().Generate(typesAndEvents); 28 | } 29 | 30 | protected static bool IsValidParameters(IEvent eventDetails) 31 | { 32 | var invokeMethod = eventDetails.GetEventType().GetDelegateInvokeMethod(); 33 | 34 | // Events must have a valid return type. 35 | if (invokeMethod == null || invokeMethod.ReturnType.FullName != "System.Void") 36 | { 37 | return false; 38 | } 39 | 40 | return !invokeMethod.Parameters.Any(x => x.IsRef); 41 | } 42 | 43 | protected abstract IEventGenerator GetEventGenerator(); 44 | 45 | protected abstract IEnumerable<(ITypeDefinition TypeHostingEvent, ITypeDefinition? BaseTypeDefinition, IEnumerable Events)> GetValidEventDetails(ICompilation compilation); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/Resolvers/INamespaceResolver.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | using ICSharpCode.Decompiler.TypeSystem; 9 | 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | 12 | namespace Pharmacist.Core.Generation.Resolvers 13 | { 14 | /// 15 | /// A resolver which will generate namespace information. 16 | /// 17 | internal interface INamespaceResolver 18 | { 19 | /// 20 | /// Creates the namespaces from the specified assembly definitions. 21 | /// 22 | /// The compilation to use to determine the dependencies. 23 | /// A collection of namespace definitions. 24 | IEnumerable Create(ICompilation compilation); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/RoslynHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using Microsoft.CodeAnalysis.CSharp; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace Pharmacist.Core.Generation 10 | { 11 | /// 12 | /// Helper methods associated with the roslyn template generators. 13 | /// 14 | internal static class RoslynHelpers 15 | { 16 | internal const string ObservableUnitName = "global::System.Reactive.Unit"; 17 | internal const string VoidType = "System.Void"; 18 | 19 | /// 20 | /// Gets an argument which access System.Reactive.Unit.Default member. 21 | /// 22 | public static ArgumentListSyntax ReactiveUnitArgumentList { get; } = SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(ObservableUnitName + ".Default")))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/TypeDefinitionNameComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using ICSharpCode.Decompiler.TypeSystem; 9 | 10 | namespace Pharmacist.Core.Generation 11 | { 12 | /// 13 | /// A comparer which will compare names. 14 | /// 15 | internal class TypeDefinitionNameComparer : IEqualityComparer, IComparer 16 | { 17 | public static TypeDefinitionNameComparer Default { get; } = new(); 18 | 19 | /// 20 | public bool Equals(ITypeDefinition? x, ITypeDefinition? y) 21 | { 22 | return StringComparer.Ordinal.Equals(x?.GenerateFullGenericName(), y?.GenerateFullGenericName()); 23 | } 24 | 25 | /// 26 | public int GetHashCode(ITypeDefinition obj) 27 | { 28 | return StringComparer.Ordinal.GetHashCode(obj.GenerateFullGenericName()); 29 | } 30 | 31 | /// 32 | public int Compare(ITypeDefinition? x, ITypeDefinition? y) 33 | { 34 | return x switch 35 | { 36 | null when y == null => 0, 37 | null => -1, 38 | _ => y == null ? 1 : string.CompareOrdinal(x.GenerateFullGenericName(), y.GenerateFullGenericName()) 39 | }; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Generation/TypeNameComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using ICSharpCode.Decompiler.TypeSystem; 9 | 10 | namespace Pharmacist.Core.Generation 11 | { 12 | internal class TypeNameComparer : IEqualityComparer, IComparer 13 | { 14 | public static TypeNameComparer Default { get; } = new(); 15 | 16 | /// 17 | public bool Equals(IType? x, IType? y) 18 | { 19 | return StringComparer.Ordinal.Equals(x?.GenerateFullGenericName(), y?.GenerateFullGenericName()); 20 | } 21 | 22 | /// 23 | public int GetHashCode(IType obj) 24 | { 25 | return StringComparer.Ordinal.GetHashCode(obj.GenerateFullGenericName()); 26 | } 27 | 28 | /// 29 | public int Compare(IType? x, IType? y) 30 | { 31 | return x switch 32 | { 33 | null when y == null => 0, 34 | null => -1, 35 | _ => y == null ? 1 : string.CompareOrdinal(x.GenerateFullGenericName(), y.GenerateFullGenericName()) 36 | }; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Pharmacist.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0;net6.0;net7.0;net462 4 | latest 5 | false 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/PlatformHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Runtime.InteropServices; 8 | 9 | namespace Pharmacist.Core 10 | { 11 | /// 12 | /// Platform helper methods. 13 | /// 14 | public static class PlatformHelper 15 | { 16 | private static readonly Lazy _IsRunningOnMono = new(() => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); 17 | 18 | /// 19 | /// Determines whether the platform is running on mono. 20 | /// 21 | /// 22 | /// true if [is running on mono]; otherwise, false. 23 | /// 24 | public static bool IsRunningOnMono() 25 | { 26 | return _IsRunningOnMono.Value; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: InternalsVisibleTo("Pharmacist.Benchmarks")] 9 | [assembly: InternalsVisibleTo("Pharmacist.Tests")] 10 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/ReferenceLocators/ReferenceLocationNotFoundException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Runtime.Serialization; 8 | 9 | namespace Pharmacist.Core.ReferenceLocators 10 | { 11 | /// 12 | /// Exception that happens when a reference cannot be located. 13 | /// 14 | [Serializable] 15 | public class ReferenceLocationNotFoundException : Exception 16 | { 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// The error message. 21 | public ReferenceLocationNotFoundException(string message) 22 | : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Initializes a new instance of the class. 28 | /// 29 | /// The error message. 30 | /// A inner exception with more error details. 31 | public ReferenceLocationNotFoundException(string message, Exception innerException) 32 | : base(message, innerException) 33 | { 34 | } 35 | 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | public ReferenceLocationNotFoundException() 40 | { 41 | } 42 | 43 | /// 44 | /// Initializes a new instance of the class. 45 | /// 46 | /// The serialization information. 47 | /// The serialization context. 48 | protected ReferenceLocationNotFoundException(SerializationInfo info, StreamingContext context) 49 | : base(info, context) 50 | { 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/TemplateManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.IO; 8 | using System.Reflection; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace Pharmacist.Core 13 | { 14 | internal static class TemplateManager 15 | { 16 | /// 17 | /// Gets the template for the header of the file. 18 | /// 19 | public const string HeaderTemplate = "Pharmacist.Core.Templates.HeaderTemplate.txt"; 20 | 21 | public static async Task GetTemplateAsync(string templateName) 22 | { 23 | var assembly = Assembly.GetExecutingAssembly(); 24 | 25 | var manifestStream = assembly.GetManifestResourceStream(templateName); 26 | 27 | if (manifestStream is null) 28 | { 29 | throw new InvalidOperationException("Could not find the valid template"); 30 | } 31 | 32 | using var streamReader = new StreamReader(manifestStream, Encoding.UTF8); 33 | return await streamReader.ReadToEndAsync().ConfigureAwait(false); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Templates/HeaderTemplate.txt: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | //------------------------------------------------------------------------------ 6 | // 7 | // This code was generated from a template. 8 | // 9 | // Manual changes to this file may cause unexpected behavior in your application. 10 | // Manual changes to this file will be overwritten if the code is regenerated. 11 | // 12 | //------------------------------------------------------------------------------ 13 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Utilities/FileSystemHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IO; 9 | using System.Linq; 10 | 11 | namespace Pharmacist.Core.Utilities 12 | { 13 | internal static class FileSystemHelpers 14 | { 15 | public static IEnumerable GetSubdirectoriesWithMatch(IEnumerable directories, ISet extensions) 16 | { 17 | var searchStack = new Stack(directories.Select(x => new DirectoryInfo(x))); 18 | 19 | while (searchStack.Count != 0) 20 | { 21 | var directoryInfo = searchStack.Pop(); 22 | 23 | if (directoryInfo.EnumerateFiles().Any(file => extensions.Contains(file.Extension))) 24 | { 25 | yield return directoryInfo.FullName; 26 | } 27 | 28 | foreach (var directory in directoryInfo.EnumerateDirectories()) 29 | { 30 | searchStack.Push(directory); 31 | } 32 | } 33 | } 34 | 35 | public static IEnumerable GetFilesWithinSubdirectories(IEnumerable directories) 36 | { 37 | return GetFilesWithinSubdirectories(directories, AssemblyHelpers.AssemblyFileExtensionsSet); 38 | } 39 | 40 | public static IEnumerable GetFilesWithinSubdirectories(IEnumerable directories, ISet extensions) 41 | { 42 | if (extensions == null) 43 | { 44 | throw new ArgumentNullException(nameof(extensions)); 45 | } 46 | 47 | var searchStack = new Stack(directories.Select(x => new DirectoryInfo(x))); 48 | 49 | while (searchStack.Count != 0) 50 | { 51 | var directoryInfo = searchStack.Pop(); 52 | 53 | foreach (var file in directoryInfo.EnumerateFiles().Where(file => extensions.Contains(file.Extension))) 54 | { 55 | yield return file.FullName; 56 | } 57 | 58 | foreach (var directory in directoryInfo.EnumerateDirectories()) 59 | { 60 | searchStack.Push(directory); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Utilities/QueueExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | namespace Pharmacist.Core.Utilities 9 | { 10 | /// 11 | /// Helper methods with queues. 12 | /// 13 | internal static class QueueExtensions 14 | { 15 | public static void EnqueueRange(this Queue queue, IEnumerable items) 16 | { 17 | foreach (var item in items) 18 | { 19 | queue.Enqueue(item); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Pharmacist.Core/Utilities/StackExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | namespace Pharmacist.Core.Utilities 10 | { 11 | /// 12 | /// Extension methods for stack based operations. 13 | /// 14 | internal static class StackExtensions 15 | { 16 | public static void PushRange(this Stack stack, IEnumerable items) 17 | { 18 | foreach (var item in items) 19 | { 20 | stack.Push(item); 21 | } 22 | } 23 | 24 | public static int TryPopRange(this Stack stack, T[] items) 25 | { 26 | return TryPopRange(stack, items, 0, items.Length); 27 | } 28 | 29 | public static int TryPopRange(this Stack stack, T[] items, int startIndex, int count) 30 | { 31 | if (items == null) 32 | { 33 | throw new ArgumentNullException(nameof(items)); 34 | } 35 | 36 | if (count < 0) 37 | { 38 | throw new ArgumentOutOfRangeException(nameof(count), "The count must be greater than 0."); 39 | } 40 | 41 | var length = items.Length; 42 | if (startIndex >= length || startIndex < 0) 43 | { 44 | throw new ArgumentOutOfRangeException(nameof(startIndex), "The start index is out of range. It must between 0 and less than the length of the array."); 45 | } 46 | 47 | if (length - count < startIndex) 48 | { 49 | // instead of (startIndex + count > items.Length) to prevent overflow 50 | throw new ArgumentException("The start index is out of range. It must between 0 and less than the length of the array."); 51 | } 52 | 53 | if (count == 0) 54 | { 55 | return 0; 56 | } 57 | 58 | var nodesCount = stack.Count > count ? count : stack.Count; 59 | 60 | for (var i = startIndex; i < startIndex + nodesCount; i++) 61 | { 62 | items[i] = stack.Pop(); 63 | } 64 | 65 | return nodesCount; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Pharmacist.IntegrationTest/InstanceClass.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | 8 | namespace Pharmacist.IntegrationTest 9 | { 10 | /// 11 | /// Provides test instances of instance class events. 12 | /// 13 | public class InstanceClass 14 | { 15 | /// 16 | /// An event for actions. 17 | /// 18 | public event Action ActionEvent; 19 | 20 | /// 21 | /// Gets an event that has a int parameter. 22 | /// 23 | public event Action IntActionEvent; 24 | 25 | /// 26 | /// Gets an event that has a string parameter. 27 | /// 28 | public event Action IntStringActionEvent; 29 | 30 | /// 31 | /// Gets an event that uses a event handler. 32 | /// 33 | public event EventHandler EventHandlerEvent; 34 | 35 | /// 36 | /// Invokes the event. 37 | /// 38 | protected virtual void OnActionEvent() 39 | { 40 | ActionEvent?.Invoke(); 41 | } 42 | 43 | /// 44 | /// Invokes the event. 45 | /// 46 | /// The parameter being passed. 47 | protected virtual void OnIntActionEvent(int arg) 48 | { 49 | IntActionEvent?.Invoke(arg); 50 | } 51 | 52 | /// 53 | /// Invokes the event. 54 | /// 55 | /// The first parameter being passed. 56 | /// The second parameter being passed. 57 | protected virtual void OnIntStringActionEvent(int arg1, string arg2) 58 | { 59 | IntStringActionEvent?.Invoke(arg1, arg2); 60 | } 61 | 62 | /// 63 | /// Invokes the event. 64 | /// 65 | protected virtual void OnEventHandlerEvent() 66 | { 67 | EventHandlerEvent?.Invoke(this, EventArgs.Empty); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Pharmacist.IntegrationTest/Pharmacist.IntegrationTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net6.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Pharmacist.MsBuild.NuGet/Pharmacist.MsBuild.NuGet.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | $(TargetFrameworks);net462 6 | Pharmacist.MSBuild 7 | Pharmacist.MSBuild 8 | 9 | true 10 | false 11 | Produces from NuGet packages System.Reactive Observables for all events within the NuGet packages inside the project.. 12 | $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs 13 | $(NoWarn);CA1819 14 | latest 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/Pharmacist.MsBuild.TargetFramework/PharmacistTargetFrameworkTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.IO; 9 | using Microsoft.Build.Framework; 10 | using Microsoft.Build.Utilities; 11 | using Pharmacist.Core; 12 | using Pharmacist.Core.NuGet; 13 | using Splat; 14 | 15 | namespace Pharmacist.MsBuild.TargetFramework 16 | { 17 | /// 18 | /// A task for generating events. 19 | /// 20 | [SuppressMessage("Design", "CA1031: Catch specific exceptions", Justification = "Final logging location for exceptions.")] 21 | public class PharmacistTargetFrameworkTask : Task, IEnableLogger 22 | { 23 | /// 24 | /// Gets or sets the target framework. 25 | /// 26 | [Required] 27 | public string TargetFramework { get; set; } 28 | 29 | /// 30 | /// Gets or sets the output file. 31 | /// 32 | [Required] 33 | public string OutputFile { get; set; } 34 | 35 | /// 36 | public override bool Execute() 37 | { 38 | var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new MsBuildLogger(Log, LogLevel.Debug), type))); 39 | Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager)); 40 | 41 | if (string.IsNullOrWhiteSpace(OutputFile)) 42 | { 43 | Log.LogError($"{nameof(OutputFile)} is not set"); 44 | return false; 45 | } 46 | 47 | if (string.IsNullOrWhiteSpace(TargetFramework)) 48 | { 49 | Log.LogError($"{nameof(TargetFramework)} is not set"); 50 | return false; 51 | } 52 | 53 | using (var writer = new StreamWriter(Path.Combine(OutputFile))) 54 | { 55 | var frameworks = TargetFramework.ToFrameworks(); 56 | ObservablesForEventGenerator.WriteHeader(writer, frameworks[0]).ConfigureAwait(false).GetAwaiter().GetResult(); 57 | 58 | try 59 | { 60 | ObservablesForEventGenerator.ExtractEventsFromTargetFramework(writer, frameworks).GetAwaiter().GetResult(); 61 | } 62 | catch (Exception ex) 63 | { 64 | this.Log().Error(ex); 65 | return false; 66 | } 67 | } 68 | 69 | return true; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Pharmacist.MsBuild.TargetFramework/targets/Pharmacist.MSBuild.TargetFramework.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | $(CoreCompileDependsOn); 6 | GeneratePharmacistTargetFramework; 7 | 8 | 9 | 10 | 11 | $(MSBuildProjectDirectory)\obj\$(Configuration)\ 12 | $(MSBuildThisFileDirectory)..\..\build\netstandard2.0\Pharmacist.MSBuild.TargetFramework.dll 13 | $(MSBuildThisFileDirectory)..\..\build\net472\Pharmacist.MSBuild.TargetFramework.dll 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/AssemblyIntegrationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.IO; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using FluentAssertions; 10 | using NuGet.Frameworks; 11 | using NuGet.Packaging.Core; 12 | using NuGet.Versioning; 13 | 14 | using Pharmacist.Core; 15 | using Pharmacist.Core.NuGet; 16 | 17 | using Xunit; 18 | 19 | namespace Pharmacist.Tests 20 | { 21 | /// 22 | /// Tests for testing different assemblies. 23 | /// 24 | public class AssemblyIntegrationTests 25 | { 26 | /// 27 | /// Tests to make sure the Tizen platform produces the expected results. 28 | /// 29 | /// A task to monitor the progress. 30 | [Fact] 31 | public async Task IntegrationTestAssemblyTest() 32 | { 33 | using var memoryStream = new MemoryStream(); 34 | var input = await NuGetPackageHelper.DownloadPackageFilesAndFolder(new[] { new PackageIdentity("NETStandard.Library", new NuGetVersion("2.0.0")) }).ConfigureAwait(false); 35 | 36 | using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true)) 37 | { 38 | await ObservablesForEventGenerator.ExtractEventsFromAssemblies(streamWriter, input, FrameworkConstants.CommonFrameworks.NetStandard20).ConfigureAwait(false); 39 | } 40 | 41 | memoryStream.Flush(); 42 | 43 | memoryStream.Position = 0; 44 | using var sr = new StreamReader(memoryStream); 45 | var contents = sr.ReadToEnd(); 46 | 47 | contents.Should().NotBeEmpty(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/IntegrationTests/Approved/Uno.Core.1.27.0.net472.approved.txt: -------------------------------------------------------------------------------- 1 | 2 | using global::System; 3 | using global::System.Reactive; 4 | using global::System.Reactive.Linq; 5 | using global::System.Reactive.Subjects; 6 | using global::Pharmacist.Common; 7 | 8 | namespace Uno 9 | { 10 | /// 11 | /// A class that contains extension methods to wrap events for classes contained within the namespace. 12 | /// 13 | public static class EventExtensions 14 | { 15 | /// 16 | /// A wrapper class which wraps all the events contained within the class. 17 | /// 18 | public static RxILoadableEvents Events(this global::Uno.ILoadable item) => new RxILoadableEvents(item); 19 | } 20 | 21 | /// 22 | /// A class which wraps the events contained within the class as observables. 23 | /// 24 | public class RxILoadableEvents 25 | { 26 | private readonly global::Uno.ILoadable _data; 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The class that is being wrapped. 31 | public RxILoadableEvents(global::Uno.ILoadable data) 32 | { 33 | _data = data; 34 | } 35 | 36 | /// 37 | /// Gets an observable which signals when the event triggers. 38 | /// 39 | public global::System.IObservable Loaded => global::System.Reactive.Linq.Observable.FromEvent, global::System.EventArgs>(eventHandler => 40 | { 41 | void Handler(object sender, global::System.EventArgs e) => eventHandler(e); 42 | return Handler; 43 | }, x => _data.Loaded += x, x => _data.Loaded -= x); 44 | } 45 | } -------------------------------------------------------------------------------- /src/Pharmacist.Tests/IntegrationTests/Approved/Uno.Core.1.27.0.net5.0.approved.txt: -------------------------------------------------------------------------------- 1 | 2 | using global::System; 3 | using global::System.Reactive; 4 | using global::System.Reactive.Linq; 5 | using global::System.Reactive.Subjects; 6 | using global::Pharmacist.Common; 7 | 8 | namespace Uno 9 | { 10 | /// 11 | /// A class that contains extension methods to wrap events for classes contained within the namespace. 12 | /// 13 | public static class EventExtensions 14 | { 15 | /// 16 | /// A wrapper class which wraps all the events contained within the class. 17 | /// 18 | public static RxILoadableEvents Events(this global::Uno.ILoadable item) => new RxILoadableEvents(item); 19 | } 20 | 21 | /// 22 | /// A class which wraps the events contained within the class as observables. 23 | /// 24 | public class RxILoadableEvents 25 | { 26 | private readonly global::Uno.ILoadable _data; 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The class that is being wrapped. 31 | public RxILoadableEvents(global::Uno.ILoadable data) 32 | { 33 | _data = data; 34 | } 35 | 36 | /// 37 | /// Gets an observable which signals when the event triggers. 38 | /// 39 | public global::System.IObservable Loaded => global::System.Reactive.Linq.Observable.FromEvent, global::System.EventArgs>(eventHandler => 40 | { 41 | void Handler(object sender, global::System.EventArgs e) => eventHandler(e); 42 | return Handler; 43 | }, x => _data.Loaded += x, x => _data.Loaded -= x); 44 | } 45 | } -------------------------------------------------------------------------------- /src/Pharmacist.Tests/IntegrationTests/Approved/Uno.Core.1.27.0.netstandard2.0.approved.txt: -------------------------------------------------------------------------------- 1 | 2 | using global::System; 3 | using global::System.Reactive; 4 | using global::System.Reactive.Linq; 5 | using global::System.Reactive.Subjects; 6 | using global::Pharmacist.Common; 7 | 8 | namespace Uno 9 | { 10 | /// 11 | /// A class that contains extension methods to wrap events for classes contained within the namespace. 12 | /// 13 | public static class EventExtensions 14 | { 15 | /// 16 | /// A wrapper class which wraps all the events contained within the class. 17 | /// 18 | public static RxILoadableEvents Events(this global::Uno.ILoadable item) => new RxILoadableEvents(item); 19 | } 20 | 21 | /// 22 | /// A class which wraps the events contained within the class as observables. 23 | /// 24 | public class RxILoadableEvents 25 | { 26 | private readonly global::Uno.ILoadable _data; 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The class that is being wrapped. 31 | public RxILoadableEvents(global::Uno.ILoadable data) 32 | { 33 | _data = data; 34 | } 35 | 36 | /// 37 | /// Gets an observable which signals when the event triggers. 38 | /// 39 | public global::System.IObservable Loaded => global::System.Reactive.Linq.Observable.FromEvent, global::System.EventArgs>(eventHandler => 40 | { 41 | void Handler(object sender, global::System.EventArgs e) => eventHandler(e); 42 | return Handler; 43 | }, x => _data.Loaded += x, x => _data.Loaded -= x); 44 | } 45 | } -------------------------------------------------------------------------------- /src/Pharmacist.Tests/IntegrationTests/Approved/Uno.Core.1.27.0.uap10.0.17763.approved.txt: -------------------------------------------------------------------------------- 1 | 2 | using global::System; 3 | using global::System.Reactive; 4 | using global::System.Reactive.Linq; 5 | using global::System.Reactive.Subjects; 6 | using global::Pharmacist.Common; 7 | 8 | namespace Uno 9 | { 10 | /// 11 | /// A class that contains extension methods to wrap events for classes contained within the namespace. 12 | /// 13 | public static class EventExtensions 14 | { 15 | /// 16 | /// A wrapper class which wraps all the events contained within the class. 17 | /// 18 | public static RxILoadableEvents Events(this global::Uno.ILoadable item) => new RxILoadableEvents(item); 19 | } 20 | 21 | /// 22 | /// A class which wraps the events contained within the class as observables. 23 | /// 24 | public class RxILoadableEvents 25 | { 26 | private readonly global::Uno.ILoadable _data; 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The class that is being wrapped. 31 | public RxILoadableEvents(global::Uno.ILoadable data) 32 | { 33 | _data = data; 34 | } 35 | 36 | /// 37 | /// Gets an observable which signals when the event triggers. 38 | /// 39 | public global::System.IObservable Loaded => global::System.Reactive.Linq.Observable.FromEvent, global::System.EventArgs>(eventHandler => 40 | { 41 | void Handler(object sender, global::System.EventArgs e) => eventHandler(e); 42 | return Handler; 43 | }, x => _data.Loaded += x, x => _data.Loaded -= x); 44 | } 45 | } -------------------------------------------------------------------------------- /src/Pharmacist.Tests/IntegrationTests/LibraryRangeNugetTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Threading.Tasks; 7 | 8 | using NuGet.LibraryModel; 9 | using NuGet.Versioning; 10 | 11 | using Pharmacist.Core.NuGet; 12 | 13 | using Xunit; 14 | 15 | namespace Pharmacist.Tests.IntegrationTests 16 | { 17 | public class LibraryRangeNuGetTest 18 | { 19 | [Theory] 20 | [InlineData("Xamarin.Forms", "4.*", "MonoAndroid10.0")] 21 | [InlineData("Xamarin.Forms", "4.*", "MonoAndroid90")] 22 | [InlineData("Xamarin.Forms", "4.*", "tizen40")] 23 | [InlineData("Xamarin.Forms", "4.*", "uap10.0.17763")] 24 | [InlineData("Xamarin.Forms", "4.*", "Xamarin.iOS10")] 25 | [InlineData("Xamarin.Forms", "4.*", "Xamarin.Mac20")] 26 | [InlineData("Xamarin.Forms", "4.*", "netstandard2.0")] 27 | [InlineData("Xamarin.Essentials", "1.*", "MonoAndroid81")] 28 | [InlineData("Xamarin.Essentials", "1.*", "MonoAndroid90")] 29 | [InlineData("Xamarin.Essentials", "1.*", "uap10.0.17763")] 30 | [InlineData("Xamarin.Essentials", "1.*", "Xamarin.iOS10")] 31 | [InlineData("Xamarin.Essentials", "1.*", "Xamarin.Mac20")] 32 | [InlineData("Xamarin.Essentials", "1.*", "netstandard2.0")] 33 | [InlineData("Tizen.NET.API4", "4.*", "netstandard2.0")] 34 | [InlineData("Avalonia", "0.9.*", "netstandard2.0")] 35 | [InlineData("Avalonia", "0.9.*", "net5.0")] 36 | [InlineData("Avalonia", "0.9.*", "net472")] 37 | [InlineData("Avalonia.Remote.Protocol", "0.9.*", "netstandard2.0")] 38 | [InlineData("Uno.UI", "1.44.*", "netstandard2.0")] 39 | [InlineData("Uno.UI", "1.44.*", "MonoAndroid80")] 40 | [InlineData("Uno.UI", "1.44.*", "MonoAndroid90")] 41 | [InlineData("Uno.UI", "1.44.*", "Xamarin.iOS10")] 42 | [InlineData("Uno.Core", "1.27.*", "netstandard2.0")] 43 | [InlineData("Uno.Core", "1.27.*", "net472")] 44 | [InlineData("Uno.Core", "1.27.*", "uap10.0.17763")] 45 | [InlineData("Uno.Core", "1.27.*", "net5.0")] 46 | public Task ProcessLibraryRange(string packageName, string nugetVersion, string framework) 47 | { 48 | var package = new[] { new LibraryRange(packageName, VersionRange.Parse(nugetVersion), LibraryDependencyTarget.Package) }; 49 | 50 | return IntegrationTestHelper.CheckResultsAgainstTemplate(package, framework.ToFrameworks()); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/Pharmacist.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | false 6 | $(NoWarn);1591;SA1633;SA1600;CA1307 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers; buildtransitive 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | all 38 | runtime; build; native; contentfiles; analyzers; buildtransitive 39 | 40 | 41 | 42 | 43 | 44 | 45 | PreserveNewest 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/ReferenceLocationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System.Runtime.InteropServices; 7 | using Pharmacist.Core.ReferenceLocators; 8 | 9 | using Xunit; 10 | 11 | namespace Pharmacist.Tests 12 | { 13 | public class ReferenceLocationTests 14 | { 15 | [Fact] 16 | public void GetsValidLocation() 17 | { 18 | var location = ReferenceLocator.GetReferenceLocation(); 19 | 20 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 21 | { 22 | Assert.Contains("Visual Studio", location); 23 | } 24 | 25 | if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) 26 | { 27 | Assert.Contains("/Library/Frameworks", location); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/TestUtilities.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. 2 | // Licensed to the .NET Foundation under one or more agreements. 3 | // The .NET Foundation licenses this file to you under the MIT license. 4 | // See the LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics.CodeAnalysis; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Runtime.CompilerServices; 12 | using Xunit; 13 | 14 | namespace Pharmacist.Tests 15 | { 16 | /// 17 | /// Some extension methods to make tests easier. 18 | /// 19 | public static class TestUtilities 20 | { 21 | private static readonly string NuGetBaseDirectory = Path.Combine(Path.GetTempPath(), "Pharmacist.Tests"); 22 | 23 | [SuppressMessage("Design", "CA1031: Catch specific exceptions", Justification = "Test utility only.")] 24 | static TestUtilities() 25 | { 26 | try 27 | { 28 | Directory.Delete(NuGetBaseDirectory, true); 29 | } 30 | catch 31 | { 32 | } 33 | } 34 | 35 | public static string GetPackageDirectory([CallerMemberName]string callerMemberName = null, [CallerFilePath]string callerMemberFilePath = null) => Path.Combine(NuGetBaseDirectory, Path.GetFileName(callerMemberFilePath), callerMemberName); 36 | 37 | [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed. Suppression is OK here.")] 38 | public static void ShouldHaveSameContents(this IEnumerable expected, IEnumerable actual) 39 | { 40 | var expectedValues = expected.ToList(); 41 | var actualValues = actual.ToList(); 42 | Assert.True( 43 | !expectedValues.Except(actualValues).Any() && expectedValues.Count == actualValues.Count, 44 | "Collections do not match." + 45 | $"{Environment.NewLine}Collection Actual Found:{Environment.NewLine}{string.Join(Environment.NewLine, actualValues)}" + 46 | $"{Environment.NewLine}Collection Expected:{Environment.NewLine}{string.Join(Environment.NewLine, expectedValues)}"); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Pharmacist.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json", 3 | "shadowCopy": false, 4 | "diagnosticMessages": true 5 | } 6 | -------------------------------------------------------------------------------- /src/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "msbuild-sdks": { 3 | "MSBuild.Sdk.Extras": "3.0.44" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "indentation": { 5 | "useTabs": false, 6 | "indentationSize": 4 7 | }, 8 | "documentationRules": { 9 | "documentExposedElements": true, 10 | "documentInternalElements": false, 11 | "documentPrivateElements": false, 12 | "documentInterfaces": true, 13 | "documentPrivateFields": false, 14 | "documentationCulture": "en-US", 15 | "companyName": ".NET Foundation and Contributors", 16 | "copyrightText": "Copyright (c) 2019-2020 {companyName}. All rights reserved.\nLicensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the {licenseName} license.\nSee the {licenseFile} file in the project root for full license information.", 17 | "variables": { 18 | "licenseName": "MIT", 19 | "licenseFile": "LICENSE" 20 | }, 21 | "xmlHeader": false 22 | }, 23 | "layoutRules": { 24 | "newlineAtEndOfFile": "allow", 25 | "allowConsecutiveUsings": true 26 | }, 27 | "maintainabilityRules": { 28 | "topLevelTypes": [ 29 | "class", 30 | "interface", 31 | "struct", 32 | "enum", 33 | "delegate" 34 | ] 35 | }, 36 | "orderingRules": { 37 | "usingDirectivesPlacement": "outsideNamespace", 38 | "systemUsingDirectivesFirst": true 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.2", 3 | "publicReleaseRefSpec": [ 4 | "^refs/heads/main$", // we release out of master 5 | "^refs/heads/rel/\\d+\\.\\d+\\.\\d+" // we also release branches starting with rel/N.N.N 6 | ], 7 | "nugetPackageVersion":{ 8 | "semVer": 2 9 | }, 10 | "cloudBuild": { 11 | "setVersionVariables": true, 12 | "buildNumber": { 13 | "enabled": false 14 | } 15 | } 16 | } 17 | --------------------------------------------------------------------------------