private CodeTypeDeclaration processRecord(Schema schema, CodeNamespace ns)
{
RecordSchema recordSchema = schema as RecordSchema;
CodeNamespace recordNamespace = null;
if (string.IsNullOrEmpty(recordSchema.name.space) && null!=ns)
recordNamespace = ns;
else
recordNamespace = addNamespace(recordSchema.name.space);
CodeTypeReference refRecord = new CodeTypeReference(recordSchema.name.name);
_SchemaToCodeTypeReferenceLookup.Add(schema, refRecord);
CodeTypeDeclaration recordDeclare = createCodeTypeDeclaration(refRecord.BaseType);
recordDeclare.Attributes = MemberAttributes.Public;
recordDeclare.IsClass = true;
recordDeclare.IsPartial = true;
/* FIXME: Thiru
foreach (Field field in recordSchema.Fields)
{
if (SchemaType.NULL == field.Schema.type)
{
//TODO: Look into this. It just feels wrong. I don't understand the need for a null field, but can this be stubbed out so that it will at least generate a field with type of object?
if (log.IsDebugEnabled) log.DebugFormat("Skipping field \"{0}\" because it is null", field.Name);
continue;
}
CodeTypeReference fieldType = getCodeTypeReference(field.Schema);
if (null == fieldType)
{
processSchema(ns, field.Schema);
fieldType = getCodeTypeReference(field.Schema);
if (null == fieldType)
{
throw new Exception("Field Schema \"" + field.Schema + "\" not found.");
}
}
CodeCommentStatement propertyComment = string.IsNullOrEmpty(field.Documentation) ? null : createDocComment(field.Documentation);
string privFieldName = string.Concat("_", field.Name);
CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), privFieldName);
CodeMemberField codeField = new CodeMemberField(fieldType, fieldRef.FieldName);
codeField.Attributes = MemberAttributes.Private;
if (null != propertyComment)
codeField.Comments.Add(propertyComment);
recordDeclare.Members.Add(codeField);
CodeMemberProperty property = new CodeMemberProperty();
property.Attributes = MemberAttributes.Public|MemberAttributes.Final;
property.Name = field.Name;
property.Type = fieldType;
addFieldAttribute(field, property);
property.GetStatements.Add(new CodeMethodReturnStatement(fieldRef));
property.SetStatements.Add(new CodeAssignStatement(fieldRef, new CodePropertySetValueReferenceExpression()));
if (null != propertyComment)
property.Comments.Add(propertyComment);
recordDeclare.Members.Add(property);
}
*/
recordNamespace.Types.Add(recordDeclare);
return recordDeclare;
}