public void TypeTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly); var derivedFromBase = TypeDefinitionData.FromType(typeof(DerivedFromBase)); var derivedFromSpecializedBase = TypeDefinitionData.FromType(typeof(DerivedFromSpecializedBase)); var derivedFromOtherBase = TypeDefinitionData.FromType(typeof(DerivedFromOtherBase)); var breakingChanges = MetadataComparer.CompareTypes(derivedFromBase, derivedFromSpecializedBase); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when the new type derives from a more specialized base class."); breakingChanges = MetadataComparer.CompareTypes(derivedFromBase, derivedFromOtherBase); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a different base class."); Assert.AreEqual(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(derivedFromBase, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(derivedFromOtherBase, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(derivedFromSpecializedBase, derivedFromBase); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a less specialized base class."); Assert.AreEqual(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(derivedFromSpecializedBase, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(derivedFromBase, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(derivedFromSpecializedBase, derivedFromOtherBase); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when the new type derives from a different base class."); Assert.AreEqual(BreakingChangeKind.IncompatibleClassHierarchy, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(derivedFromSpecializedBase, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(derivedFromOtherBase, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public void TypeTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedClassToStaticTests).Assembly); var Class = TypeDefinitionData.FromType(typeof(Class)); var ClassWithInternalConstructor = TypeDefinitionData.FromType(typeof(ClassWithInternalConstructor)); var ClassWithProtectedConstructor = TypeDefinitionData.FromType(typeof(ClassWithProtectedConstructor)); var StaticClass = TypeDefinitionData.FromType(typeof(StaticClass)); var breakingChanges = MetadataComparer.CompareTypes(Class, StaticClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToStatic).ToList(); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a class is made static."); Assert.AreEqual(BreakingChangeKind.ChangedClassToStatic, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(Class, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(StaticClass, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(ClassWithInternalConstructor, StaticClass); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a class with no public constructors is made abstract."); breakingChanges = MetadataComparer.CompareTypes(ClassWithProtectedConstructor, StaticClass).Where(b => b.BreakingChangeKind == BreakingChangeKind.ChangedClassToStatic).ToList(); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a class is made static."); Assert.AreEqual(BreakingChangeKind.ChangedClassToStatic, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(ClassWithProtectedConstructor, breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(StaticClass, breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); }
public AssemblyData CreateAssemblyData(string assemblyMetadataPath) { var assemblyMetadata = _jsonFileProvider.Load <AssemblyMetadata>(assemblyMetadataPath); bool isExtension = assemblyMetadata.AssemblyModelType.EqualsIgnoreCase(TemplateSetConventions.Extension); string assemblyName = GetAssemblyName(assemblyMetadataPath); var schemaName = isExtension ? ExtensionsConventions.GetProperCaseNameForLogicalName( _domainModelsDefinitionsProvidersByProjectName[assemblyName] .GetDomainModelDefinitions() .SchemaDefinition.LogicalName) : EdFiConventions.ProperCaseName; var assemblyData = new AssemblyData { AssemblyName = assemblyName, Path = Path.GetDirectoryName(assemblyMetadataPath), TemplateSet = assemblyMetadata.AssemblyModelType, IsProfile = assemblyMetadata.AssemblyModelType.EqualsIgnoreCase(TemplateSetConventions.Profile), SchemaName = schemaName, IsExtension = isExtension }; return(assemblyData); }
public void LoadAssembly() { ModuleDefinition module = ModuleDefinition.ReadModule(FullPath, App.CurrentProject.ReaderParams); if (module != null) { // Add the assembly module to our dictionary assemblyData = new AssemblyData(FullPath, module); // Create global namespace assemblyData.AddNamespace("", new NamespaceData("-")); NamespaceData namespaceData; // Find namespaces in the loaded assembly foreach (TypeDefinition type in module.Types) { bool existingNamespace = assemblyData.Namespaces.TryGetValue(type.Namespace, out namespaceData); if (!existingNamespace) { namespaceData = new NamespaceData(type.Namespace); assemblyData.AddNamespace(type.Namespace, namespaceData); } namespaceData.Add(type); } } }
// Builds a lookup table of class+method name. // // It's easier to build it at once by enumerating, once we have the table, we // can use the symbolIds to look up the sources when we need them. private static AssemblyData FetchSymbolData(IDiaSession session) { // This will be a *flat* enumerator of all classes. // // A nested class will not contain a '+' in it's name, just a '.' separating the parent class name from // the child class name. IDiaEnumSymbols diaClasses; session.findChildren( session.globalScope, // Search at the top-level. SymTagEnum.SymTagCompiland, // Just find classes. name: null, // Don't filter by name. compareFlags: 0u, // doesn't matter because name is null. ppResult: out diaClasses); var assemblyData = new AssemblyData(); // Resist the urge to use foreach here. It doesn't work well with these APIs. var classesFetched = 0u; IDiaSymbol diaClass; diaClasses.Next(1u, out diaClass, out classesFetched); while (classesFetched == 1 && diaClass != null) { var classData = new ClassData() { Name = diaClass.name, SymbolId = diaClass.symIndexId, }; assemblyData.Classes.Add(diaClass.name, classData); IDiaEnumSymbols diaMethods; session.findChildren( diaClass, SymTagEnum.SymTagFunction, name: null, // Don't filter by name. compareFlags: 0u, // doesn't matter because name is null. ppResult: out diaMethods); // Resist the urge to use foreach here. It doesn't work well with these APIs. var methodsFetched = 0u; IDiaSymbol diaMethod; diaMethods.Next(1u, out diaMethod, out methodsFetched); while (methodsFetched == 1 && diaMethod != null) { classData.Methods[diaMethod.name] = new MethodData() { Name = diaMethod.name, SymbolId = diaMethod.symIndexId, }; diaMethods.Next(1u, out diaMethod, out methodsFetched); } diaClasses.Next(1u, out diaClass, out classesFetched); } return(assemblyData); }
public void GenericParameterRenameTest() { var assembly = AssemblyData.FromAssembly(typeof(MiscellaneousTests).Assembly); var typeData1 = TypeDefinitionData.FromType(typeof(GenericParameter1 <>)); var typeData2 = TypeDefinitionData.FromType(typeof(GenericParameter2 <>)); var typeData3 = TypeDefinitionData.FromType(typeof(GenericParameter3 <,>)); var typeData4 = TypeDefinitionData.FromType(typeof(GenericParameter4 <,>)); var breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter."); breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4); Assert.AreEqual(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type."); Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type."); typeData1 = TypeDefinitionData.FromType(typeof(GenericMethodParameter1)); typeData2 = TypeDefinitionData.FromType(typeof(GenericMethodParameter2)); typeData3 = TypeDefinitionData.FromType(typeof(GenericMethodParameter3)); typeData4 = TypeDefinitionData.FromType(typeof(GenericMethodParameter4)); breakingChanges = MetadataComparer.CompareTypes(typeData1, typeData2); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes for renaming a class's generic type parameter."); breakingChanges = MetadataComparer.CompareTypes(typeData3, typeData4); Assert.AreEqual(1, breakingChanges.Count, "There should be a breaking changes for using a different generic type parameter position as a return type."); Assert.AreEqual(BreakingChangeKind.ChangedMemberType, breakingChanges[0].BreakingChangeKind, "There should be a breaking changes for using a different generic type parameter position as a return type."); }
public void OperatorDataAllOperatorsTest() { var t = typeof(VariousMemberFeatures); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); Assert.IsNotNull(typeData.GetMember("op_Implicit")); Assert.IsNotNull(typeData.GetMember("op_Explicit")); Assert.IsNotNull(typeData.GetMember("op_Addition")); Assert.IsNotNull(typeData.GetMember("op_Subtraction")); Assert.IsNotNull(typeData.GetMember("op_Multiply")); Assert.IsNotNull(typeData.GetMember("op_Division")); Assert.IsNotNull(typeData.GetMember("op_Modulus")); Assert.IsNotNull(typeData.GetMember("op_ExclusiveOr")); Assert.IsNotNull(typeData.GetMember("op_BitwiseAnd")); Assert.IsNotNull(typeData.GetMember("op_BitwiseOr")); Assert.IsNotNull(typeData.GetMember("op_LeftShift")); Assert.IsNotNull(typeData.GetMember("op_RightShift")); Assert.IsNotNull(typeData.GetMember("op_Equality")); Assert.IsNotNull(typeData.GetMember("op_GreaterThan")); Assert.IsNotNull(typeData.GetMember("op_LessThan")); Assert.IsNotNull(typeData.GetMember("op_Inequality")); Assert.IsNotNull(typeData.GetMember("op_GreaterThanOrEqual")); Assert.IsNotNull(typeData.GetMember("op_LessThanOrEqual")); Assert.IsNotNull(typeData.GetMember("op_Decrement")); Assert.IsNotNull(typeData.GetMember("op_Increment")); Assert.IsNotNull(typeData.GetMember("op_UnaryNegation")); Assert.IsNotNull(typeData.GetMember("op_UnaryPlus")); Assert.IsNotNull(typeData.GetMember("op_OnesComplement")); Assert.IsNotNull(typeData.GetMember("op_LogicalNot")); Assert.IsNotNull(typeData.GetMember("op_True")); Assert.IsNotNull(typeData.GetMember("op_False")); }
public void Initialize() { string path = @"..\..\TestDLL\Faker.dll"; Assembly assembly = Assembly.LoadFrom(path); assemblyData = new AssemblyData(assembly); }
public void IndexerTests() { var assembly = AssemblyData.FromAssembly(typeof(RemovedOverrideOfAbstractMemberTests).Assembly); var IndexerVirtual = TypeDefinitionData.FromType(typeof(IndexerVirtual)); var IndexerAbstract = TypeDefinitionData.FromType(typeof(IndexerAbstract)); var IndexerVirtualOverride = TypeDefinitionData.FromType(typeof(IndexerVirtualOverride)); var IndexerAbstractOverride = TypeDefinitionData.FromType(typeof(IndexerAbstractOverride)); var IndexerVirtualOverrideInternalConstructor = TypeDefinitionData.FromType(typeof(IndexerVirtualOverrideInternalConstructor)); var IndexerAbstractOverrideInternalConstructor = TypeDefinitionData.FromType(typeof(IndexerAbstractOverrideInternalConstructor)); var IndexerVirtualNoOverride = TypeDefinitionData.FromType(typeof(IndexerVirtualNoOverride)); var IndexerAbstractNoOverride = TypeDefinitionData.FromType(typeof(IndexerAbstractNoOverride)); var breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualOverride, IndexerVirtualNoOverride); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an override of a virtual member is removed."); breakingChanges = MetadataComparer.CompareTypes(IndexerVirtualOverrideInternalConstructor, IndexerVirtualNoOverride); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an override of a virtual member is removed and there are no externally visible constructors."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractOverride, IndexerAbstractNoOverride); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an override of an abstract member is removed."); Assert.AreEqual(BreakingChangeKind.RemovedOverrideOfAbstractMember, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerAbstractOverride.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.IsNull(breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.AreEqual(IndexerAbstractNoOverride, breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstractOverrideInternalConstructor, IndexerAbstractNoOverride); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when an override of an abstract member is removed and there are no externally visible constructors."); }
public void SetData(AssemblyData assembly) { AssemblyData = assembly; AssemblyName.text = $"{AssemblyData.Assembly.GetName().Name} [{AssemblyData.Types.Count}]"; m_types.ForEach(go => Destroy(go)); m_types.Clear(); foreach (var type in AssemblyData.Types) { var typeDisplayGO = Instantiate(TypeDisplay.gameObject); m_types.Add(typeDisplayGO); typeDisplayGO.transform.SetParent(transform); var typeDisplay = typeDisplayGO.GetComponentInChildren <Text>(); typeDisplay.text = type.Name; var img = typeDisplayGO.GetComponent <Image>(); var skin = UiReferenceTracker.LevelInstance.Skin; if (typeof(IState).IsAssignableFrom(type)) { img.color = skin.StateColor; } else if (typeof(IStateMachineDefinition).IsAssignableFrom(type)) { img.color = skin.StateMachineDefinitionColor; } else if (typeof(ICondition).IsAssignableFrom(type)) { img.color = skin.ConditionColor; } else { img.color = skin.NeutralColor; } typeDisplayGO.SetActive(Toggle.isOn); } }
private static object Union(AssemblyData thisAssembly, AssemblyData thatAssembly) { Union(thisAssembly.AssemblyName, thatAssembly.AssemblyName); if (thatAssembly.Types != null) { if (thisAssembly.Types == null) { thisAssembly.Types = new JsonDictionary <string, JsonDictionary <string, TypeData> >(); } foreach (KeyValuePair <string, JsonDictionary <string, TypeData> > nspace in thatAssembly.Types) { if (!thisAssembly.Types.ContainsKey(nspace.Key)) { thisAssembly.Types.Add(nspace.Key, nspace.Value); continue; } thisAssembly.Types[nspace.Key] = DictionaryUnion(thisAssembly.Types[nspace.Key], nspace.Value, Union); } } return(thisAssembly); }
private Program() { Console.WriteLine("Press d to run DatabaseRepository or f to run FileRepository"); char modeRepository = Char.Parse(Console.ReadLine()); Console.WriteLine("Press w to run WindowMode or c to run ConsoleMode"); char modeView = Char.Parse(Console.ReadLine()); GetNames(modeRepository, modeView); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(this.viewTypeName, "*." + this.viewTypeExtension)); catalog.Catalogs.Add(new DirectoryCatalog(this.loggerName, "*.dll")); catalog.Catalogs.Add(new DirectoryCatalog(this.serializerName, "*.dll")); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); _container = new CompositionContainer(catalog); try { this._container.ComposeParts(this); } catch (CompositionException compositionException) { Console.WriteLine(compositionException.ToString()); } string pathToDll = "../../../Reflection/bin/Debug/Reflection.dll"; Reflector reflector = new Reflector(); reflector.Reflect(pathToDll, this.logger); this.assemblyData = reflector._AssemblyModel; }
public void IndexerTests() { var assembly = AssemblyData.FromAssembly(typeof(AddedAbstractMemberTests).Assembly); var IndexerNonVirtual = TypeDefinitionData.FromType(typeof(IndexerNonVirtual)); var IndexerVirtual = TypeDefinitionData.FromType(typeof(IndexerVirtual)); var IndexerAbstract = TypeDefinitionData.FromType(typeof(IndexerAbstract)); var breakingChanges = MetadataComparer.CompareTypes(IndexerVirtual, IndexerNonVirtual); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a virtual member changes to non-virtual."); Assert.AreEqual(BreakingChangeKind.ChangedMemberToNonVirtual, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerVirtual.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerNonVirtual.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerAbstract, IndexerNonVirtual); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when an abstract member changes to non-virtual."); Assert.AreEqual(BreakingChangeKind.ChangedMemberToNonVirtual, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(IndexerAbstract.GetMember("Item"), breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(IndexerNonVirtual.GetMember("Item"), breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(IndexerNonVirtual, IndexerVirtual); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a non-virtual member changes to virtual."); }
public Assembly?Load(AssemblyData assemblyData) { try { lock (_assemblyLoadContextLock) { if (_assemblyLoadContext == null) { return(null); } if (assemblyData.PdbBytes != null) { return(_assemblyLoadContext.LoadFromStream( new MemoryStream(assemblyData.DllBytes), new MemoryStream(assemblyData.PdbBytes))); } return(_assemblyLoadContext.LoadFromStream( new MemoryStream(assemblyData.DllBytes))); } } catch { } return(null); }
public void TypeDefinitionDataIsExtensionsClassTest() { var assembly = AssemblyData.FromAssembly(typeof(TypeDefinitionDataTests).Assembly); Assert.IsFalse(TypeDefinitionData.FromType(typeof(StaticClass)).IsExtensionsClass, "The IsExtensionsClass value is incorrect."); Assert.IsTrue(TypeDefinitionData.FromType(typeof(ExtensionsClass)).IsExtensionsClass, "The IsExtensionsClass value is incorrect."); }
public void TypeDefinitionDataMembersInStructTest() { var t = typeof(TestStructDefinition); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); Assert.IsNotNull(typeData, "Unable to create a TypeDefinitionData instance from the TestClassDefinition type."); TestUtilities.VerifyMember <ConstantData>(typeData, "Constant"); TestUtilities.VerifyInstanceAndStaticMember <FieldData>(typeData, "Field"); TestUtilities.VerifyInstanceAndStaticMember <FieldData>(typeData, "FieldReadOnly"); var members = typeData.GetMembers(".ctor"); Assert.AreEqual(1, members.Count, "Incorrect number of constructors returned."); Assert.AreEqual(1, ((ConstructorData)members[0]).Parameters.Count, "The public constructor should have been returned."); TestUtilities.VerifyInstanceAndStaticMember <EventData>(typeData, "Event"); TestUtilities.VerifyInstanceAndStaticMember <EventData>(typeData, "EventCustom"); members = typeData.GetMembers("Item"); Assert.AreEqual(1, members.Count, "Incorrect number of indexers returned."); Assert.AreEqual(1, ((IndexerData)members[0]).Parameters.Count, "The public indexer should have been returned."); TestUtilities.VerifyInstanceAndStaticMember <MethodData>(typeData, "Method"); var member = (OperatorData)typeData.GetMember("op_Addition"); Assert.IsNotNull(member, "OperatorData instances should be returned."); TestUtilities.VerifyInstanceAndStaticMember <PropertyData>(typeData, "Property"); TestUtilities.VerifyMember <TypeDefinitionData>(typeData, "NestedStruct"); }
private TypeData ReadTypeDataBase(AssemblyData assemblyData) { var typeId = _reader.ReadUInt32(); var name = _reader.ReadString(); var accessibility = (Accessibility)_reader.ReadByte(); var memberFlags = (MemberFlags)_reader.ReadByte(); var typeKind = (TypeKind)_reader.ReadByte(); var delegateReturnTypeIsDynamic = _reader.ReadBoolean(); TypeData type; var isTypeData = _reader.ReadBoolean(); if (isTypeData) { var typeFlags = (TypeDefinitionFlags)_reader.ReadByte(); var hasFullName = _reader.ReadBoolean(); var fullName = hasFullName ? _reader.ReadString() : null; type = new TypeDefinitionData(name, accessibility, memberFlags, typeKind, assemblyData, fullName, typeFlags, delegateReturnTypeIsDynamic); } else { var genericParameterAttributes = (GenericParameterAttributes)_reader.ReadInt32(); var genericParameterPosition = (int)_reader.ReadUInt16(); type = new GenericTypeParameterData(name, accessibility, memberFlags, typeKind, assemblyData, genericParameterAttributes, genericParameterPosition); } _typeTable.Add(typeId, type); return(type); }
private static void AddFileDependencies(PackageDef pkg, AssemblyData dependency, AssemblyData foundAsm) { var depender = pkg.Files.FirstOrDefault(f => f.DependentAssemblies.Contains(dependency)); if (depender == null) { log.Warning("Adding dependent assembly '{0}' to package. It was not found in any other packages.", Path.GetFileName(foundAsm.Location)); } else { log.Info($"'{Path.GetFileName(depender.FileName)}' dependents on '{dependency.Name}' version '{dependency.Version}'. Adding dependency to package, it was not found in any other packages."); } var destPath = string.Format("Dependencies/{0}.{1}/{2}", Path.GetFileNameWithoutExtension(foundAsm.Location), foundAsm.Version.ToString(), Path.GetFileName(foundAsm.Location)); pkg.Files.Add(new PackageFile { SourcePath = foundAsm.Location, RelativeDestinationPath = destPath, DependentAssemblies = foundAsm.References.ToList() }); // Copy the file to the actual directory so we can rely on it actually existing where we say the package has it. if (!File.Exists(destPath)) { Directory.CreateDirectory(Path.GetDirectoryName(destPath)); ProgramHelper.FileCopy(foundAsm.Location, destPath); } }
public void EventDataMemberFlagsTest() { var t = typeof(OverloadedMemberFeatures); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); var eventData = (EventData)typeData.GetMember("EventInstance"); Assert.AreEqual(MemberFlags.None, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventStatic"); Assert.AreEqual(MemberFlags.Static, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceAbstract"); Assert.AreEqual(MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceVirtual"); Assert.AreEqual(MemberFlags.Virtual, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideAbstract"); Assert.AreEqual(MemberFlags.Override, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideAbstractSealed"); Assert.AreEqual(MemberFlags.Override | MemberFlags.Sealed, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideAbstractAbstract"); Assert.AreEqual(MemberFlags.Override | MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideVirtual"); Assert.AreEqual(MemberFlags.Override, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideVirtualSealed"); Assert.AreEqual(MemberFlags.Override | MemberFlags.Sealed, eventData.MemberFlags, "The Flags value of the member is wrong."); eventData = (EventData)typeData.GetMember("EventInstanceOverrideVirtualAbstract"); Assert.AreEqual(MemberFlags.Override | MemberFlags.Abstract, eventData.MemberFlags, "The Flags value of the member is wrong."); }
public void GenericTypeParameterDataContraintsTest() { var t = typeof(TestClassDefinition <, , , ,>); var assembly = AssemblyData.FromAssembly(t.Assembly); var testClassDefinitionData = TypeDefinitionData.FromType(t); var equatableInterfaceData = ConstructedGenericTypeData.FromType <IEquatable <TestClassDefinition> >(); var testInterfaceDefinitionData = TypeDefinitionData.FromType <TestInterfaceDefinition>(); var valueTypeData = TypeDefinitionData.FromType <ValueType>(); var p1 = testClassDefinitionData.GenericParameters[0]; Assert.AreEqual(0, p1.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect."); var p2 = testClassDefinitionData.GenericParameters[1]; Assert.AreEqual(2, p2.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect."); // Note: these may need to be reversed Assert.AreEqual(equatableInterfaceData, p2.Constraints[0], "The reported type is not correct."); Assert.AreEqual(testInterfaceDefinitionData, p2.Constraints[1], "The reported type is not correct."); var p3 = testClassDefinitionData.GenericParameters[2]; Assert.AreEqual(0, p3.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect."); var p4 = testClassDefinitionData.GenericParameters[3]; Assert.AreEqual(1, p4.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect."); Assert.AreEqual(valueTypeData, p4.Constraints[0], "The reported type is not correct."); var p5 = testClassDefinitionData.GenericParameters[4]; Assert.AreEqual(0, p5.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect."); }
protected override void Arrange() { _assemblyData = new AssemblyData { AssemblyName = "testAssembly", Path = "testFolder", TemplateSet = "standard", IsExtension = false, IsProfile = true, SchemaName = EdFiConventions.ProperCaseName }; var domainModelDefinition = new DomainModelDefinitions { SchemaDefinition = new SchemaDefinition("Ed-Fi", "edfi") }; var domainModelDefinitionsProvider = Stub <IDomainModelDefinitionsProvider>(); A.CallTo(() => domainModelDefinitionsProvider.GetDomainModelDefinitions()) .Returns(domainModelDefinition); _domainModelDefinitionsProviders = new[] { domainModelDefinitionsProvider }; _domainModelDefinitionsProviderProvider = Stub <IDomainModelDefinitionsProviderProvider>(); A.CallTo(() => _domainModelDefinitionsProviderProvider.DomainModelDefinitionProviders()) .Returns(_domainModelDefinitionsProviders); _templateContextProvider = new TemplateContextProvider(_domainModelDefinitionsProviderProvider); }
public Assembly?Load(AssemblyData assemblyData) { try { lock (_domainLock) { if (_domain == null) { return(null); } if (assemblyData.PdbBytes != null) { return(_domain.Load( assemblyData.DllBytes, assemblyData.PdbBytes)); } return(_domain.Load(assemblyData.DllBytes)); } } catch { return(null); } }
public void IndexerDataMemberFlagsTest() { var t = typeof(OverloadedMemberFeatures); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); var members = typeData.GetMembers("Item"); Assert.AreEqual(9, members.Count, "Incorrect number of indexers"); var indexerData = (IndexerData)members[0]; Assert.AreEqual(MemberFlags.None, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[1]; Assert.AreEqual(MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[2]; Assert.AreEqual(MemberFlags.Virtual, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[3]; Assert.AreEqual(MemberFlags.Override, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[4]; Assert.AreEqual(MemberFlags.Override | MemberFlags.Sealed, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[5]; Assert.AreEqual(MemberFlags.Override | MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[6]; Assert.AreEqual(MemberFlags.Override, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[7]; Assert.AreEqual(MemberFlags.Override | MemberFlags.Sealed, indexerData.MemberFlags, "The Flags value of the member is wrong."); indexerData = (IndexerData)members[8]; Assert.AreEqual(MemberFlags.Override | MemberFlags.Abstract, indexerData.MemberFlags, "The Flags value of the member is wrong."); }
private bool EnsureInitialized() { if (_isInitialized.HasValue) { return(_isInitialized.Value); } if (_project == null) { _logger.LogWarning("No project information. No source information will be available."); _isInitialized = false; return(_isInitialized.Value); } try { _diaDataSource = (IDiaDataSource) new DiaDataSource(); _isInitialized = true; } catch (Exception ex) { _logger.LogWarning("Failed to create DIA DataSource. No source information will be available.", ex); _isInitialized = false; return(_isInitialized.Value); } // We have a project, and we successfully loaded DIA, so let's capture the symbols // and create a session. try { var context = new CapturingLoadContext(); var assemblyName = new AssemblyName(_project.Name); _project.Load(assemblyName, context); _assembly = Assembly.Load(assemblyName); _diaDataSource.loadDataFromIStream(new StreamWrapper(context.Symbols)); _diaDataSource.openSession(out _diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to load symbols. No source information will be available.", ex); _isInitialized = false; return(_isInitialized.Value); } try { _assemblyData = FetchSymbolData(_diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to read symbols. No source information will be available.", ex); _isInitialized = false; return(_isInitialized.Value); } _isInitialized = true; return(_isInitialized.Value); }
public void ConstructorTests() { var assembly = AssemblyData.FromAssembly(typeof(ChangedAccessibilityFromPublicToProtectedTests).Assembly); var publicConstructor = TypeDefinitionData.FromType(typeof(PublicConstructor)); var protectedConstructor = TypeDefinitionData.FromType(typeof(ProtectedConstructor)); var protectedInternalConstructor = TypeDefinitionData.FromType(typeof(ProtectedInternalConstructor)); var breakingChanges = MetadataComparer.CompareTypes(publicConstructor, protectedConstructor); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a constant is changed from public to protected"); Assert.AreEqual(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(PublicConstructor)).GetMembers(".ctor")[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(ProtectedConstructor)).GetMembers(".ctor")[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(publicConstructor, protectedInternalConstructor); Assert.AreEqual(1, breakingChanges.Count, "There should be one breaking change when a constructor is changed from public to protected internal"); Assert.AreEqual(BreakingChangeKind.ChangedAccessibilityFromPublicToProtected, breakingChanges[0].BreakingChangeKind, "The BreakingChangeKind is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(PublicConstructor)).GetMembers(".ctor")[0], breakingChanges[0].OldItem, "The OldItem is incorrect."); Assert.AreEqual(TypeDefinitionData.FromType(typeof(ProtectedInternalConstructor)).GetMembers(".ctor")[0], breakingChanges[0].NewItem, "The NewItem is incorrect."); Assert.IsNull(breakingChanges[0].AssociatedData, "The AssociatedData is incorrect."); breakingChanges = MetadataComparer.CompareTypes(protectedConstructor, publicConstructor); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected to public"); breakingChanges = MetadataComparer.CompareTypes(protectedConstructor, protectedInternalConstructor); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected to protected internal"); breakingChanges = MetadataComparer.CompareTypes(protectedInternalConstructor, publicConstructor); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected internal to public"); breakingChanges = MetadataComparer.CompareTypes(protectedInternalConstructor, protectedConstructor); Assert.AreEqual(0, breakingChanges.Count, "There should be no breaking changes when a constructor is changed from protected internal to protected"); }
public static CompressionResult Compress(AssemblyData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var fi = new FileInfo(data.SourcePath); if (!fi.Exists) { throw new InvalidOperationException($"File '{data.SourcePath}' does not exist"); } // if ((ulong)fi.Length > InputAssemblySizeLimit) { // return CompressionResult.InputTooBig; // } data.DestinationPath = $"{data.SourcePath}.lz4"; data.SourceSize = (uint)fi.Length; byte[] sourceBytes = null; byte[] destBytes = null; try { sourceBytes = bytePool.Rent(checked ((int)fi.Length)); using (var fs = File.Open(data.SourcePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { fs.Read(sourceBytes, 0, (int)fi.Length); } destBytes = bytePool.Rent(LZ4Codec.MaximumOutputSize(sourceBytes.Length)); int encodedLength = LZ4Codec.Encode(sourceBytes, 0, checked ((int)fi.Length), destBytes, 0, destBytes.Length, LZ4Level.L09_HC); if (encodedLength < 0) { return(CompressionResult.EncodingFailed); } data.DestinationSize = (uint)encodedLength; using (var fs = File.Open(data.DestinationPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { using (var bw = new BinaryWriter(fs)) { bw.Write(CompressedDataMagic); // magic bw.Write(data.DescriptorIndex); // index into runtime array of descriptors bw.Write(checked ((uint)fi.Length)); // file size before compression bw.Write(destBytes, 0, encodedLength); bw.Flush(); } } } finally { if (sourceBytes != null) { bytePool.Return(sourceBytes); } if (destBytes != null) { bytePool.Return(destBytes); } } return(CompressionResult.Success); }
public AssemblyViewModel(AssemblyData assemblyData) { _assemblyData = assemblyData; _assemblyName = assemblyData.Name; _namespaces = new ObservableCollection <NamespaceViewModel>(); CreateNamespaces(); }
public void EventDataAccessibilityTest() { var t = typeof(TestClassDefinition); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); TestUtilities.VerifyAccessibility(typeData, "EventInstance"); }
public void TypeDefinitionDataAccessibilityTest() { var t = typeof(TestClassDefinition); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); TestUtilities.VerifyAccessibility(typeData, "NestedStruct"); }
public void TypeDefinitionDataAssemblyTest() { var t = typeof(TestClassDefinition); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); Assert.AreEqual(assembly, typeData.AssemblyData, "The Assembly reference is not assigned correctly."); }
public void TypeDefinitionDataNameTest() { var t = typeof(TestClassDefinition); var assembly = AssemblyData.FromAssembly(t.Assembly); var typeData = TypeDefinitionData.FromType(t); Assert.AreEqual(t.Name, typeData.Name, "The Name is not assigned correctly."); }
public RuntimeAssemblyManager() { _fullNameToAssemblyDataMap = new Dictionary<string, AssemblyData>(StringComparer.OrdinalIgnoreCase); _mvidToAssemblyDataMap = new Dictionary<Guid, AssemblyData>(); _loadedAssemblies = new HashSet<Assembly>(); _mainMvids = new List<Guid>(); var currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += AssemblyResolve; currentDomain.AssemblyLoad += AssemblyLoad; CLRHelpers.ReflectionOnlyAssemblyResolve += ReflectionOnlyAssemblyResolve; _preloadedSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var assembly in currentDomain.GetAssemblies()) { var assemblyData = new AssemblyData(assembly); _preloadedSet.Add(assemblyData.Id.SimpleName); AddAssemblyData(assemblyData); } }
private void AddAssemblyData(AssemblyData assemblyData) { _fullNameToAssemblyDataMap.Add(assemblyData.Id.FullName, assemblyData); _mvidToAssemblyDataMap.Add(assemblyData.Id.Mvid, assemblyData); }
private bool TryGetMatchingByFullName(ModuleDataId id, out AssemblyData assemblyData, out bool fullMatch) { if (_fullNameToAssemblyDataMap.TryGetValue(id.FullName, out assemblyData)) { fullMatch = _preloadedSet.Contains(id.SimpleName) || id.Mvid == assemblyData.Id.Mvid; return true; } assemblyData = default(AssemblyData); fullMatch = false; return false; }
// Builds a lookup table of class+method name. // // It's easier to build it at once by enumerating, once we have the table, we // can use the symbolIds to look up the sources when we need them. private static AssemblyData FetchSymbolData(IDiaSession session) { // This will be a *flat* enumerator of all classes. // // A nested class will not contain a '+' in it's name, just a '.' separating the parent class name from // the child class name. IDiaEnumSymbols diaClasses; session.findChildren( session.globalScope, // Search at the top-level. SymTagEnum.SymTagCompiland, // Just find classes. name: null, // Don't filter by name. compareFlags: 0u, // doesn't matter because name is null. ppResult: out diaClasses); var assemblyData = new AssemblyData(); // Resist the urge to use foreach here. It doesn't work well with these APIs. var classesFetched = 0u; IDiaSymbol diaClass; diaClasses.Next(1u, out diaClass, out classesFetched); while (classesFetched == 1 && diaClass != null) { var classData = new ClassData() { Name = diaClass.name, SymbolId = diaClass.symIndexId, }; assemblyData.Classes.Add(diaClass.name, classData); IDiaEnumSymbols diaMethods; session.findChildren( diaClass, SymTagEnum.SymTagFunction, name: null, // Don't filter by name. compareFlags: 0u, // doesn't matter because name is null. ppResult: out diaMethods); // Resist the urge to use foreach here. It doesn't work well with these APIs. var methodsFetched = 0u; IDiaSymbol diaMethod; diaMethods.Next(1u, out diaMethod, out methodsFetched); while (methodsFetched == 1 && diaMethod != null) { classData.Methods[diaMethod.name] = new MethodData() { Name = diaMethod.name, SymbolId = diaMethod.symIndexId, }; diaMethods.Next(1u, out diaMethod, out methodsFetched); } diaClasses.Next(1u, out diaClass, out classesFetched); } return assemblyData; }
private bool EnsureInitialized() { if (_isInitialized.HasValue) { return _isInitialized.Value; } if (_project == null) { _logger.LogWarning("No project information. No source information will be available."); _isInitialized = false; return _isInitialized.Value; } try { _diaDataSource = (IDiaDataSource)new DiaDataSource(); _isInitialized = true; } catch (Exception ex) { _logger.LogWarning("Failed to create DIA DataSource. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } // We have a project, and we successfully loaded DIA, so let's capture the symbols // and create a session. try { var context = new CapturingLoadContext(); _project.Load(context); _diaDataSource.loadDataFromIStream(new StreamWrapper(context.Symbols)); _diaDataSource.openSession(out _diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to load symbols. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } try { _assemblyData = FetchSymbolData(_diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to read symbols. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } _isInitialized = true; return _isInitialized.Value; }
private bool EnsureInitialized() { if (_isInitialized.HasValue) { return _isInitialized.Value; } try { _diaDataSource = (IDiaDataSource)new DiaDataSource(); _isInitialized = true; } catch (Exception ex) { _logger.LogWarning("Failed to create DIA DataSource. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } // We have a project, and we successfully loaded DIA, so let's capture the symbols // and create a session. try { _diaDataSource.loadDataFromPdb(_pdbPath); _diaDataSource.openSession(out _diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to load symbols. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } try { _assemblyData = FetchSymbolData(_diaSession); } catch (Exception ex) { _logger.LogWarning("Failed to read symbols. No source information will be available.", ex); _isInitialized = false; return _isInitialized.Value; } _isInitialized = true; return _isInitialized.Value; }