private bool IfAlreadyCreatedReturn(BoundGenericTypeDefinitionMask_I genericBlueprint, BoundTypeDefinitionMask_I[] typeArgumentTypes, out SemanticTypeDefinitionMask_I ensure) { for (int i = 0; i < genericBlueprint.Instances.Count; i++) { var instance = genericBlueprint.Instances[i]; var currentInstance = (BoundGenericTypeDefinitionMask_I)instance; var found = true; for (var j = 0; j < currentInstance.TypeArguments.All.Count; j++) { var currentTypeArgument = currentInstance.TypeArguments.All[j]; if (ReferenceEquals(currentTypeArgument, typeArgumentTypes[j])) { continue; } found = false; break; } if (found) { ensure = currentInstance; return(true); } } ensure = null; return(false); }
public FieldInfo[] GetFieldsFromCollection(BoundGenericTypeDefinitionMask_I inputBlueprint) { if (!(inputBlueprint is BoundTypeDefinitionWithFieldsMask_I withFields)) { throw new System.Exception("GenericClassDefinition should have fields if this type has fields."); } var collection = withFields.Fields.ByName.Values.ToList(); FieldInfo[] fields = new FieldInfo[withFields.Fields.ByName.Count]; for (int i = 0; i < collection.Count; i++) { var semantic = collection[i]; if (!(semantic is BoundFieldDefinitionMask_I bound)) { throw new System.Exception("Semantic field should be a bound field to use it in conversion."); } fields[i] = bound.UnderlyingField; } return(fields); }
public void BuildFields_WithGenericTypeParameters(RuntimicSystemModel semanticModel, BoundGenericTypeDefinition_I input, BoundGenericTypeDefinitionMask_I blueprint) { if (!(input is BoundTypeDefinitionWithFieldsMask_I typeWithFields)) { return; } if (!(blueprint is BoundTypeDefinitionWithFieldsMask_I bound)) { return; } var list = bound.Fields.ByName.Values.ToList(); for (int i = 0; i < list.Count; i++) { var field = list[i]; typeWithFields.Fields.ByName.Add(field.Name, field); } }
private ConstructorBuildInfo[] GetConstructorsFromCollection(ILConversion conversion, ConvertedGenericTypeDefinitionMask_I input, BoundGenericTypeDefinitionMask_I inputBlueprint) { if (!(inputBlueprint is BoundTypeDefinitionWithConstructorsMask_I withConstructors)) { throw new System.Exception($"The generic type definition should have constructors if the instance has constructors. Could not cast the " + $"argument {nameof(inputBlueprint)} to {typeof(BoundTypeDefinitionWithConstructorsMask_I)}."); } var constructors = new ConstructorBuildInfo[withConstructors.Constructors.All.Count]; for (int i = 0; i < withConstructors.Constructors.All.Count; i++) { var semantic = withConstructors.Constructors.All[i]; if (!(semantic is BoundConstructorDefinitionMask_I bound)) { throw new System.Exception("Semantic constructor should be a bound constructor to use it in conversion."); } var newTypeCreated = input.UnderlyingType; var genericTypeInstanceConstructorInfo = TypeBuilder.GetConstructor(newTypeCreated, bound.UnderlyingConstructor); constructors[i] = new ConstructorBuildInfo() { GenericTypeInstanceConstructorInfo = genericTypeInstanceConstructorInfo, GenericTypeDefinitionConstructorInfo = bound.UnderlyingConstructor, GenericTypeDefinitionBoundConstructor = bound, GenericTypeInstanceMethodReference = Cecil.Metadata.Members.Methods.Building.MethodDefinitions.MakeGenericInstanceTypeMethodReference(conversion.RuntimicSystem, (GenericInstanceType)input.SourceTypeReference, (MethodDefinition)bound.MethodReference) }; } return(constructors); }