示例#1
0
 public override string ToString()
 {
     if (SubTypes != null && SubTypes.Length > 0)
     {
         return(Identifier.ToString() + "<" + String.Join(",", SubTypes.Select(x => x.ToString())) + ">" + (Nullable ? "?" : ""));
     }
     return(Identifier.ToString() + (Nullable ? "?" : ""));
 }
示例#2
0
        public Type?GetRuntimeType()
        {
            if (Identifier == RepresentationTypeIdentifier.TypedList)
            {
                var sub = SubTypes[0].GetRuntimeType();
                if (sub == null)
                {
                    return(null);
                }

                var rt = sub.MakeArrayType();

                return(rt);
            }
            else if (Identifier == RepresentationTypeIdentifier.TypedMap)
            {
                var subs = SubTypes.Select(x => x.GetRuntimeType()).ToArray();
                var rt   = typeof(Map <,>).MakeGenericType(subs);
                return(rt);
            }

            return(Identifier switch
            {
                (RepresentationTypeIdentifier.Void) => typeof(void),
                (RepresentationTypeIdentifier.Dynamic) => typeof(object),
                (RepresentationTypeIdentifier.Bool) => Nullable ? typeof(bool?) : typeof(bool),
                (RepresentationTypeIdentifier.Char) => Nullable ? typeof(char?) : typeof(char),
                (RepresentationTypeIdentifier.UInt8) => Nullable ? typeof(byte?) : typeof(byte),
                (RepresentationTypeIdentifier.Int8) => Nullable ? typeof(sbyte?) : typeof(sbyte),
                (RepresentationTypeIdentifier.Int16) => Nullable ? typeof(short?) : typeof(short),
                (RepresentationTypeIdentifier.UInt16) => Nullable ? typeof(ushort?) : typeof(ushort),
                (RepresentationTypeIdentifier.Int32) => Nullable ? typeof(int?) : typeof(int),
                (RepresentationTypeIdentifier.UInt32) => Nullable ? typeof(uint?) : typeof(uint),
                (RepresentationTypeIdentifier.Int64) => Nullable ? typeof(ulong?) : typeof(long),
                (RepresentationTypeIdentifier.UInt64) => Nullable ? typeof(ulong?) : typeof(ulong),
                (RepresentationTypeIdentifier.Float32) => Nullable ? typeof(float?) : typeof(float),
                (RepresentationTypeIdentifier.Float64) => Nullable ? typeof(double?) : typeof(double),
                (RepresentationTypeIdentifier.Decimal) => Nullable ? typeof(decimal?) : typeof(decimal),
                (RepresentationTypeIdentifier.String) => typeof(string), //Nullable ? typeof(Nullable<string>) : typeof(string),
                (RepresentationTypeIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime),
                (RepresentationTypeIdentifier.Resource) => typeof(IResource),
                (RepresentationTypeIdentifier.Record) => typeof(IRecord),
                (RepresentationTypeIdentifier.TypedRecord) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Record).DefinedType,
                (RepresentationTypeIdentifier.TypedResource) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Unspecified).DefinedType,
                (RepresentationTypeIdentifier.Enum) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Enum).DefinedType,

                _ => null
            });
示例#3
0
        public string DisplayString()
        {
            var sb     = new StringBuilder();
            var widthA = Formatting.MaxLineLength / 2;
            var widthB = Formatting.MaxLineLength - widthA;

            // First Line
            sb.AppendLine(new string('=', Formatting.MaxLineLength));
            sb.AppendLine(string.Format("{0,-" + widthA + "}{1," + widthB + "}", Name, ManaCost));

            // Second Line
            sb.AppendLine(new string('-', Formatting.MaxLineLength));
            if (SuperType != SuperType.None)
            {
                sb.Append(SuperType + " ");
            }
            sb.Append(string.Join(" ", Types.Select(t => t.ToString())));
            if (SubTypes.Count != 0)
            {
                sb.Append(" - " + string.Join(" ", SubTypes.Select(t => t.ToString())));
            }
            sb.AppendLine();

            // Rules
            if (Text != string.Empty)
            {
                sb.AppendLine(new string('-', Formatting.MaxLineLength));
                foreach (var line in Text.Split(new char[] { '|' }))
                {
                    var words = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    sb.Append(words[0]);
                    var charCount = words[0].Length;
                    foreach (var word in words.Skip(1))
                    {
                        if (charCount + word.Length >= Formatting.MaxLineLength)
                        {
                            sb.AppendLine();
                            sb.Append(word);
                            charCount = word.Length;
                        }
                        else
                        {
                            sb.Append(' ');
                            sb.Append(word);
                            charCount += word.Length + 1;
                        }
                    }
                    sb.AppendLine();
                }
            }

            // Power / Toughness
            if (Power != string.Empty || Toughness != string.Empty)
            {
                sb.AppendLine(new string('-', Formatting.MaxLineLength));
                sb.AppendLine(string.Format("{0}/{1}", Power, Toughness));
            }

            // End
            sb.AppendLine(new string('=', Formatting.MaxLineLength));

            return(sb.ToString());
        }
示例#4
0
        /// <summary>
        /// Gets a fields value as a string suitable for things like, oh, a velocity template
        /// </summary>
        /// <param name="field">A FormFields enum value</param>
        /// <returns>The value of the field, OR, and error message</returns>
        public string GetFieldAsString(FormFields field)
        {
            try
            {
                switch (field)
                {
                case FormFields.MainType:
                {
                    return(MainType.Label);
                }

                case FormFields.SubTypes:
                {
                    return(String.Join(", ", SubTypes.Select(st => st.Label)));
                }

                case FormFields.Stages:
                {
                    return(String.Join(", ", Stages.Select(stg => stg.Label)));;
                }

                case FormFields.Findings:
                {
                    return(String.Join(", ", Findings.Select(fin => fin.Label)));
                }

                case FormFields.Age:
                {
                    return(Age.ToString());
                }

                case FormFields.Phrase:
                {
                    return(Phrase);
                }

                case FormFields.HealthyVolunteers:
                {
                    switch (_healthyVols)
                    {
                    case HealthyVolunteerType.Healthy: { return("Only Accepting Healthy Volunteers"); }

                    case HealthyVolunteerType.Infirmed: { return("Not Accepting Healthy Volunteers"); }

                    default: { return("Accepting All Volunteers"); }
                    }
                }

                case FormFields.Gender:
                {
                    return(Gender);
                }

                case FormFields.TrialTypes:
                {
                    return(String.Join(", ", TrialTypes.Select(tt => tt.Label)));
                }

                case FormFields.Drugs:
                {
                    return(String.Join(", ", Drugs.Select(d => d.Label)));
                }

                case FormFields.OtherTreatments:
                {
                    return(String.Join(", ", OtherTreatments.Select(ot => ot.Label)));;
                }

                case FormFields.TrialPhases:
                {
                    return(String.Join(", ", TrialPhases.Select(tp => tp.Label)));
                }

                case FormFields.TrialIDs:
                {
                    return(String.Join(", ", TrialIDs));
                }

                case FormFields.Investigator:
                {
                    return(Investigator);
                }

                case FormFields.LeadOrg:
                {
                    return(LeadOrg);
                }

                case FormFields.IsVAOnly:
                {
                    if (IsVAOnly)
                    {
                        return("True");
                    }
                    else
                    {
                        return("False");
                    }
                }

                case FormFields.AtNIH:
                case FormFields.City:
                case FormFields.State:
                case FormFields.Country:
                case FormFields.Hospital:
                case FormFields.ZipCode:
                case FormFields.ZipRadius:
                {
                    return(GetLocFieldAsString(field));
                }

                default:
                {
                    return("Error Retrieving Field");
                }
                }
            }
            catch (Exception)
            {
                return("Error Retrieving Field");
            }
        }