BExIS.Dlm.Services.DataStructure.DataStructureManager.AddParameterUsage C# (CSharp) Метод

AddParameterUsage() публичный Метод

The method functions in a similar way to the AddVariableUsage method, but operates on a Parameter
public AddParameterUsage ( Variable variableUsage, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description ) : Parameter
variableUsage BExIS.Dlm.Entities.DataStructure.Variable
dataAttribute BExIS.Dlm.Entities.DataStructure.DataAttribute
isValueOptional bool
label string
defaultValue string
missingValue string
description string
Результат BExIS.Dlm.Entities.DataStructure.Parameter
        public Parameter AddParameterUsage(Variable variableUsage, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description)
        {
            Contract.Requires(variableUsage != null && variableUsage.DataAttribute.Id >= 0);
            Contract.Requires(dataAttribute != null && dataAttribute.Id >= 0);
            Contract.Ensures(Contract.Result<Parameter>() != null && Contract.Result<Parameter>().Id >= 0);

            VariableRepo.Reload(variableUsage);
            VariableRepo.LoadIfNot(variableUsage.Parameters);
            int count = (from pu in variableUsage.Parameters
                         where pu.DataAttribute.Id.Equals(dataAttribute.Id)
                         select pu
                        )
                        .Count();

            // support multiple use of a data attribute as a parameter in a variable context
            //if (count > 0)
            //    throw new Exception(string.Format("Data attribute {0} is already used as a parameter in conjunction with variable {1} in data structure {2}", dataAttribute.Id, variableUsage.DataAttribute.Id, variableUsage.DataStructure.Id));

            Parameter usage = new Parameter()
            {
                DataAttribute = dataAttribute,
                Variable = variableUsage,
                MinCardinality = isValueOptional ? 0 : 1,
                // if there is no label provided, use the data attribute name and a sequence number calculated by the number of occurrences of that data attribute in the current usage
                Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? dataAttribute.Name : string.Format("{0} ({1})", dataAttribute.Name, count)),
                DefaultValue = defaultValue,
                MissingValue = missingValue,
                Description = description
            };
            dataAttribute.UsagesAsParameter.Add(usage);
            variableUsage.Parameters.Add(usage);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Parameter> repo = uow.GetRepository<Parameter>();
                repo.Put(usage);
                uow.Commit();
            }
            return (usage);
        }