public CDAttribute GetAttributeByName(String Name) { CDAttribute Result = null; foreach (CDAttribute Attribute in this.Attributes) { if (String.Equals(Attribute.Name, Name)) { Result = Attribute; break; } } return(Result); }
public Boolean AddAttribute(CDAttribute NewAttribute) { Boolean Result = true; foreach (CDAttribute Attribute in this.Attributes) { if (Attribute.Name == NewAttribute.Name) { Result = false; break; } } if (Result) { this.Attributes.Add(NewAttribute); } return(Result); }
//SetUloh1 // Similar as task above, but this time we set the attribute value to "NewValue" parameter // But it's not that easy, you need to check if attribute type and NewValue type are the same (e.g. both are integer) // To do that, you need to find the referencing variable's class (via Scope) and then the attribute's type (vie ExecutionSpace) // When you know the type of attribute, use EXETypes.IsValidValue to see if you can or cannot assign that value to that attribute // You assign it in Scope // Return if you could assign it or not // EXETypes.determineVariableType() public Boolean SetAttributeValue(String ReferencingVariableName, String AttributeName, EXEScope Scope, CDClassPool ExecutionSpace, String NewValue) { EXEReferencingVariable ReferencingVariable = Scope.FindReferencingVariableByName(ReferencingVariableName); if (ReferencingVariable == null) { return(false); } CDClassInstance ClassInstance = ExecutionSpace.GetClassInstanceById(ReferencingVariable.ClassName, ReferencingVariable.ReferencedInstanceId); if (ClassInstance == null) { return(false); } CDClass Class = ExecutionSpace.getClassByName(ReferencingVariable.ClassName); if (Class == null) { return(false); } CDAttribute Attribute = Class.GetAttributeByName(AttributeName); if (Attribute == null) { return(false); } String NewValueType = EXETypes.DetermineVariableType(null, NewValue); if (!EXETypes.CanBeAssignedToAttribute(AttributeName, Attribute.Type, NewValueType)) { return(false); } ClassInstance.SetAttribute(AttributeName, EXETypes.AdjustAssignedValue(Attribute.Type, NewValue)); return(true); }
public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace) { bool Result = false; EXEExpressionEvaluator Evaluator = new EXEExpressionEvaluator(); EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators(); EXEReferenceEvaluator AccessEvaluator = new EXEReferenceEvaluator(); // If we just calculate with ints, reals, bools, strings if (Evaluator.IsSimpleOperator(this.Operation)) { foreach (EXEASTNode Operand in this.Operands) { if (!Operand.VerifyReferences(Scope, ExecutionSpace)) { return(false); } } Result = true; } // If we have handle operators else if (HandleEvaluator.IsHandleOperator(this.Operation)) { if (this.Operands.Count() == 1 && Scope.FindReferenceHandleByName(((EXEASTNodeLeaf)this.Operands[0]).GetNodeValue()) != null) { Result = true; } } // If we have access operator - we either access attribute or have decimal number. There are always 2 operands else if (".".Equals(this.Operation) && this.Operands.Count == 2) { if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { Result = true; } else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.Operands[0].GetNodeValue()); if (Variable == null) { return(false); } CDClass Class = ExecutionSpace.getClassByName(Variable.ClassName); if (Class == null) { return(false); } CDAttribute Attribute = Class.GetAttributeByName(this.Operands[1].GetNodeValue()); if (Attribute == null) { return(false); } CDClassInstance Instance = Variable.RetrieveReferencedClassInstance(ExecutionSpace); if (Instance == null) { return(false); } Result = true; } } return(Result); }