Esempio n. 1
0
        public CSharpMethod GenerateFetchAllByAttribute(DomainEntityAttribute attribute)
        {
            String parameterName = attribute.AttributeName.Substring(0, 1).ToLower() + attribute.AttributeName.Substring(1) + "Id";

            List <String> methodCode = new List <String>();

            DomainEntityExtender[] extenders = this.Entity.Container.Domain.Containers.SelectMany(c => c.ContainerEntities).OfType <DomainEntityExtender>().Where(e => e.ReferencedEntity == this.Entity && !String.IsNullOrEmpty(e.FilterCode)).ToArray();
            methodCode.Add("IEnumerable<" + this.Entity.ReferencedTable.ProgrammaticName + "Record> recordCollection = this.Provider.DataProvider." + this.BaseEntity.Container.ContainerName + "." + this.BaseEntity.EntityName + ".FetchAllBy" + attribute.Column.ProgrammaticName + "(" + parameterName + ");");
            methodCode.Add("foreach (" + this.Entity.ReferencedTable.ProgrammaticName + "Record record in recordCollection)");
            methodCode.Add("{");
            methodCode.Add("    if (record != null" + (this.Entity.FilterCode != null ? " && " + this.Entity.FilterCode : "") + ")");
            methodCode.Add("    {");
            foreach (DomainEntityExtender extender in extenders)
            {
                methodCode.Add("        " + (extender == extenders[0] ? "if" : "else if") + " (" + extender.FilterCode + ")");
                methodCode.Add("            yield return new Local" + extender.EntityName + "Model(this.Provider, record);");
            }
            if (extenders.Length != 0)
            {
                methodCode.Add("        else");
            }
            methodCode.Add((extenders.Length == 0 ? "" : "    ") + "        yield return new Local" + this.Entity.EntityName + "Model(this.Provider, record);");
            methodCode.Add("    }");
            methodCode.Add("}");

            CSharpMethod result = new CSharpMethod(this);

            result.XmlSummary       = "Retrieves a collection of <see cref='" + this.Entity.EntityName + "Model' /> instances.";
            result.XmlReturns       = "The <see cref='" + this.Entity.EntityName + "Model' /> instances that match the specified <paramref name='" + parameterName + "' />.";
            result.MethodType       = "IEnumerable<Local" + this.Entity.EntityName + "Model>";
            result.Name             = "FetchAllBy" + attribute.AttributeName + "Id";
            result.MethodParameters = new CSharpParameter[]
            {
                new CSharpParameter()
                {
                    XmlSummary    = "The value which identifies the <see cref='" + this.Entity.EntityName + "Model' /> instances to be returned.",
                    ParameterType = attribute.Column.ProgrammaticType,
                    ParameterName = parameterName
                }
            };
            result.MethodCode = methodCode.ToArray();
            return(result);
        }
 /// <summary>
 ///     Initialises a new <see cref="AttributeEditor" /> instance.
 /// </summary>
 public AttributeEditor(DomainEntityAttribute domainEntityAttribute)
 {
     this.InitializeComponent();
     this.DomainEntityAttribute = domainEntityAttribute;
 }