コード例 #1
0
ファイル: Generator.cs プロジェクト: kpmrafeeq/DVM4T
        private CodeTypeReference GetPropertyType(Type baseType, FieldProperty fieldProp)
        {
            var config = configuration.FieldAttributeTypes[fieldProp.FieldType];
            //return new CodeTypeReference(fieldProp.IsMultiValue ? config.MultiExpectedReturnTypeName : config.SingleExpectedReturnTypeName);

            CodeTypeReference singleType = new CodeTypeReference(config.ReturnTypeName);
            CodeTypeReference result;
            if (fieldProp.FieldType == FieldType.Embedded)
            {
                singleType = new CodeTypeReference(fieldProp.EmbeddedTypeName);
            }
            else if (fieldProp.FieldType == FieldType.Linked && fieldProp.LinkedComponentTypeNames.Count == 1)
            {
                //If there's only one allowed linked type, make it the generic type
                singleType = new CodeTypeReference(fieldProp.LinkedComponentTypeNames[0]);
            }
            if (fieldProp.IsMultiValue)
            {
                if (fieldProp.FieldType == FieldType.Embedded || fieldProp.FieldType == FieldType.Linked)
                {
                    //use ViewModelList
                    result = new CodeTypeReference("ViewModelList"); //Have to use this otherwise couldn't use proper generic types
                    result.TypeArguments.Add(singleType);
                }
                else
                {
                    result = new CodeTypeReference(config.MultiExpectedReturnTypeName); //Assuming all other types implement IList
                }
            }
            else
            {
                result = singleType;
            }
            return result;
        }
コード例 #2
0
ファイル: Tridion.cs プロジェクト: kpmrafeeq/DVM4T
 private static void ProcessFields(ItemFieldDefinitionData[] fields, bool isMetadata, ref IList<FieldProperty> modelProperties)
 {
     foreach (ItemFieldDefinitionData field in fields)
     {
         var fieldProp = new FieldProperty();
         fieldProp.IsMultiValue = field.MaxOccurs != 1;
         fieldProp.IsMetadata = isMetadata;
         fieldProp.FieldName = field.Name;
         fieldProp.PropertyName = field.Name.ResolvePropertyName();
         if (field is ComponentLinkFieldDefinitionData)
         {
             //Linked component
             fieldProp.FieldType = FieldType.Linked;
             ComponentLinkFieldDefinitionData myField = field as ComponentLinkFieldDefinitionData;
             IList<string> linkedClassNames = new List<string>();
             IList<FieldProperty> linkedModelProperties = new List<FieldProperty>();
             if (myField.AllowedTargetSchemas != null)
             {
                 foreach (LinkToSchemaData link in myField.AllowedTargetSchemas)
                 {
                     fieldProp.LinkedComponentTypeNames.Add(link.Title.ResolveModelName());
                 }
             }
         }
         else if (field is EmbeddedSchemaFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Embedded;
             EmbeddedSchemaFieldDefinitionData myField = field as EmbeddedSchemaFieldDefinitionData;
             if (myField.EmbeddedSchema != null)
             {
                 fieldProp.EmbeddedTypeName = myField.EmbeddedSchema.Title.ResolveModelName();
             }
         }
         else if (field is MultiLineTextFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Text;
         }
         else if (field is KeywordFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Keyword;
         }
         else if (field is NumberFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Number;
         }
         else if (field is DateFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Date;
         }
         else if (field is ExternalLinkFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.ExternalLink;
         }
         else if (field is MultimediaLinkFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Multimedia;
         }
         else if (field is SingleLineTextFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.Text;
         }
         else if (field is XhtmlFieldDefinitionData)
         {
             fieldProp.FieldType = FieldType.RichText;
         }
         else if (field is ItemFieldDefinitionData)
         {
             //"Default"
             Console.WriteLine("Unknown type for Field: " + field.Name);
             continue; //don't add the property
         }
         modelProperties.Add(fieldProp);
     }
 }