private CodeAttributeDeclaration[] GenerateDocTypePropertyAttributes(DocTypeProperty docTypeProperty) { List <CodeAttributeDeclaration> attrs = new List <CodeAttributeDeclaration>(); CodeAttributeDeclaration umbInfoAtt = new CodeAttributeDeclaration("UmbracoInfo", new CodeAttributeArgument(new CodePrimitiveExpression(docTypeProperty.Alias)), new CodeAttributeArgument("DisplayName", new CodePrimitiveExpression(docTypeProperty.Name)), new CodeAttributeArgument("Mandatory", new CodePrimitiveExpression(docTypeProperty.Mandatory)) ); attrs.Add(umbInfoAtt); attrs.Add(new CodeAttributeDeclaration("Property")); if (this.SerializationMode == SerializationMode.Unidirectional) { CodeAttributeDeclaration dataMemberAtt = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DataMemberAttribute)), new CodeAttributeArgument("Name", new CodePrimitiveExpression(docTypeProperty.TypeName)) ); } return(attrs.ToArray()); }
private CodeMemberProperty CreateCustomProperty(DocTypeProperty docTypeProperty, string privateVariableName) { var internalTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(DataTypeRetyper).IsAssignableFrom(t) && t.GetCustomAttributes(typeof(DataTypeAttribute), true).Length == 1); var currType = internalTypes.SingleOrDefault(t => t.GetCustomAttributes(typeof(DataTypeAttribute), true).Cast <DataTypeAttribute>().First().ControlId == docTypeProperty.ControlId); if (currType != null) { var retyper = (DataTypeRetyper)Activator.CreateInstance(currType); CodeMemberProperty p = new CodeMemberProperty(); p.Type = new CodeTypeReference(retyper.MemberType); p.Name = retyper.MemberName(docTypeProperty.TypeName); p.Attributes = MemberAttributes.Public; p.HasGet = true; p.HasSet = false; new Switch(retyper) .Case <YesNoRetyper>(b => { p.GetStatements.Add(new CodeMethodReturnStatement( GenerateEqualityConditionalStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), privateVariableName) , new CodePrimitiveExpression(0) ) ) ); }, true) ; return(p); } return(null); }
private CodeMemberProperty CreateCustomProperty(DocTypeProperty docTypeProperty, string privateVariableName) { var internalTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(DataTypeRetyper).IsAssignableFrom(t) && t.GetCustomAttributes(typeof(DataTypeAttribute), true).Length == 1); var currType = internalTypes.SingleOrDefault(t => t.GetCustomAttributes(typeof(DataTypeAttribute), true).Cast<DataTypeAttribute>().First().ControlId == docTypeProperty.ControlId); if (currType != null) { var retyper = (DataTypeRetyper)Activator.CreateInstance(currType); CodeMemberProperty p = new CodeMemberProperty(); p.Type = new CodeTypeReference(retyper.MemberType); p.Name = retyper.MemberName(docTypeProperty.TypeName); p.Attributes = MemberAttributes.Public; p.HasGet = true; p.HasSet = false; new Switch(retyper) .Case<YesNoRetyper>(b => { p.GetStatements.Add(new CodeMethodReturnStatement( GenerateEqualityConditionalStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), privateVariableName) , new CodePrimitiveExpression(0) ) ) ); }, true) ; return p; } return null; }
private CodeAttributeDeclaration[] GenerateDocTypePropertyAttributes(DocTypeProperty docTypeProperty) { List<CodeAttributeDeclaration> attrs = new List<CodeAttributeDeclaration>(); CodeAttributeDeclaration umbInfoAtt = new CodeAttributeDeclaration("UmbracoInfo", new CodeAttributeArgument(new CodePrimitiveExpression(docTypeProperty.Alias)), new CodeAttributeArgument("DisplayName", new CodePrimitiveExpression(docTypeProperty.Name)), new CodeAttributeArgument("Mandatory", new CodePrimitiveExpression(docTypeProperty.Mandatory)) ); attrs.Add(umbInfoAtt); attrs.Add(new CodeAttributeDeclaration("Property")); if (this.SerializationMode == SerializationMode.Unidirectional) { CodeAttributeDeclaration dataMemberAtt = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DataMemberAttribute)), new CodeAttributeArgument("Name", new CodePrimitiveExpression(docTypeProperty.TypeName)) ); } return attrs.ToArray(); }
internal DocTypeProperty BuildProperty(IRecordsReader reader) { var p = new DocTypeProperty { Alias = reader.GetAlias(), Description = reader.GetDescription(), Id = reader.GetId(), Mandatory = reader.GetBoolean("Mandatory"), Name = reader.GetName(), RegularExpression = reader.GetString("RegularExpression"), ControlId = reader.GetGuid("ControlId") }; switch (reader.GetDbType()) { case "Date": p.DatabaseType = typeof(DateTime); break; case "Integer": p.DatabaseType = typeof(int); break; case "Ntext": case "Nvarchar": p.DatabaseType = typeof(string); break; default: p.DatabaseType = typeof(object); break; } return p; }