public bool IsElementNameUnique(string name, TLCGenObjectTypeEnum type) { foreach (var o in Uitgangen) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in Ingangen) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in HulpElementen) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in Timers) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in Counters) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in Schakelaars) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in GeheugenElementen) { if (o.Naam == name && o.ObjectType == type) { return(false); } } foreach (var o in Parameters) { if (o.Naam == name && o.ObjectType == type) { return(false); } } return(true); }
public bool IsElementIdentifierUnique(TLCGenObjectTypeEnum objectType, string identifier, bool vissim = false) { if (!vissim) { return(TLCGenIntegrityChecker.IsElementNaamUnique(Controller, identifier, objectType)); } return(TLCGenIntegrityChecker.IsElementVissimNaamUnique(Controller, identifier)); }
public void ChangeNameOnObject(object obj, string oldName, string newName, TLCGenObjectTypeEnum objectType) { if (obj == null) { return; } Type objType = obj.GetType(); // class refers to? var refToAttr = objType.GetCustomAttribute <RefersToAttribute>(); PropertyInfo[] properties = objType.GetProperties(); foreach (PropertyInfo property in properties) { object propValue = property.GetValue(obj); // for strings if (property.PropertyType == typeof(string)) { // if this is the referent string, set it if needed if (refToAttr != null && (property.Name == refToAttr.ReferProperty1 && objectType == refToAttr.ObjectType1 || property.Name == refToAttr.ReferProperty2 && objectType == refToAttr.ObjectType2 || property.Name == refToAttr.ReferProperty3 && objectType == refToAttr.ObjectType3)) { if ((string)propValue == oldName) { property.SetValue(obj, newName); } } // otherwise, check if the string has RefersTo itself, and set if needed else { var strRefToAttr = property.GetCustomAttribute <RefersToAttribute>(); if (strRefToAttr != null) { if ((string)propValue == oldName) { property.SetValue(obj, newName); } } } } // for lists else if (propValue is IList elems) { foreach (var item in elems) { ChangeNameOnObject(item, oldName, newName, objectType); } } // for objects else if (!property.PropertyType.IsValueType) { ChangeNameOnObject(propValue, oldName, newName, objectType); } } }
public RefersToAttribute(TLCGenObjectTypeEnum objectType1, string refprop1 = null, TLCGenObjectTypeEnum objectType2 = TLCGenObjectTypeEnum.Fase, string refprop2 = null, TLCGenObjectTypeEnum objectType3 = TLCGenObjectTypeEnum.Fase, string refprop3 = null) { ObjectType1 = objectType1; ObjectType2 = objectType2; ObjectType3 = objectType3; ReferProperty1 = refprop1; ReferProperty2 = refprop2; ReferProperty3 = refprop3; }
private static bool IsElementNaamUnique(object obj, string naam, TLCGenObjectTypeEnum type) { if (obj == null || string.IsNullOrWhiteSpace(naam)) { return(true); } var objType = obj.GetType(); var properties = objType.GetProperties(); foreach (var property in properties) { var ignore = (TLCGenIgnoreAttributeAttribute)property.GetCustomAttribute(typeof(TLCGenIgnoreAttributeAttribute)); if (ignore != null) { continue; } var propValue = property.GetValue(obj); if (property.PropertyType == typeof(string)) { var attr = property.GetCustomAttributes(typeof(ModelNameAttribute), true); if (attr.Length != 1) { continue; } var mnAttr = (ModelNameAttribute)attr.First(); var propString = (string)propValue; if (propString == naam && mnAttr.Type == type) { return(false); } } else if (!property.PropertyType.IsValueType) { if (propValue is IList elems) { if (elems.Cast <object>().Any(item => !IsElementNaamUnique(item, naam, type))) { return(false); } } else { if (!IsElementNaamUnique(propValue, naam, type)) { return(false); } } } } return(true); }
public NameChangingMessage(TLCGenObjectTypeEnum objectType, string oldname, string newname) { ObjectType = objectType; OldName = oldname; NewName = newname; }
/// <summary> /// Checks if an element's Name property is unique accross the ControllerModel /// </summary> /// <param name="naam">The Name property to check</param> /// <returns>True if unique, false if not</returns> public static bool IsElementNaamUnique(ControllerModel _Controller, string naam, TLCGenObjectTypeEnum type) { foreach (var pl in Plugins.TLCGenPluginManager.Default.ApplicationPlugins.Where(x => x.Item1.HasFlag(Plugins.TLCGenPluginElems.IOElementProvider))) { if (!((Plugins.ITLCGenElementProvider)pl.Item2).IsElementNameUnique(naam, type)) { return(false); } } return(IsElementNaamUnique((object)_Controller, naam, type)); }
public ModelNameAttribute(TLCGenObjectTypeEnum type) { Type = type; }
public RefersToAttribute(TLCGenObjectTypeEnum objectType, string objectTypeProperty = null) { ObjectType = objectType; ObjectTypeProperty = objectTypeProperty; }