private string GetPropertyValueAccessorMethod(PropertyInfo property) { var accessorMethod = "SingleOrDefault()"; if (property.BindedType != null) accessorMethod = string.Format("SingleOrDefault() ?? new Null{0}()", property.GetCodeType()); if (property.IsList) accessorMethod = "ToList()"; return accessorMethod; }
private static string GetParsedPropertyValue(PropertyInfo property, string variableName) { var valueToParse = variableName + ".Value"; return string.Format("string.IsNullOrEmpty({0}) ? ({1})null : {2}", valueToParse, property.GetCodeType(), TypeUtils.GetParsableType(property.XmlType).ConstructParseCall(valueToParse)); }
private string GetPropertyValueRetriever(PropertyInfo property, string collectionName) { string instanceCreation = property.IsParsable ? GetParsedPropertyValue(property, "e") : GetXElementToPropertyValue(property, "e"); return string.Format("element.{0}().Where(e => e.Name == \"{1}\").Select(e => {2})", collectionName, property.XmlName, instanceCreation); }
private void AddValueProperty(ClassInfo classInfo, XmlSchemaSimpleContentExtension sce) { var propInfo = new PropertyInfo(classInfo) { IsList = false, XmlName = "Value", XmlType = ResolveSimpleTypeName(sce.BaseTypeName.Name), IsElementValue = true }; if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); }
void AddExtensionAttributes(ClassInfo classInfo, XmlSchemaComplexType complex) { if (complex.ContentModel != null && complex.ContentModel.Content is XmlSchemaSimpleContentExtension) { var sce = complex.ContentModel.Content as XmlSchemaSimpleContentExtension; if (sce.Attributes.Count > 0) { AddAttributes(classInfo, sce.Attributes); var propInfo = new PropertyInfo(classInfo) { IsList = false, XmlName = "Value", XmlType = "Value", IsElementValue = true }; if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); } } }
private string GetXElementToPropertyValue(PropertyInfo property, string varName) { return property.BindedType != null ? string.Format("new {0}({1})", property.BindedType.GetCodeName(), varName) : string.Format("{0}.Value", varName); }
private void WriteValuePropertyInitialization(StreamWriter writer, PropertyInfo property) { var instanceCreation = property.IsParsable ? GetParsedPropertyValue(property, "element") : "element.Value"; writer.WriteLine("\t\t\t{0} = {1};", property.GetCodeName(), instanceCreation); }
private void WritePropertyInitialization(StreamWriter writer, PropertyInfo property, string collectionName) { if (property.IsElementValue) WriteValuePropertyInitialization(writer, property); else writer.WriteLine("\t\t\t{0} = {1}.{2};", property.GetCodeName(), GetPropertyValueRetriever(property, collectionName), GetPropertyValueAccessorMethod(property)); }
private PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute) { var prop = new PropertyInfo(classInfo) { XmlName = attribute.Name, XmlType = ResolveSimpleTypeName(attribute.SchemaTypeName.Name) }; return prop; }
private void ParseElementProperty(ClassInfo classInfo, XmlSchemaElement elem, bool isList, string nsCode) { var propInfo = new PropertyInfo(classInfo) { IsList = isList, XmlName = elem.Name, XmlType = ResolveTypeName(elem, nsCode) }; ParseElement(elem, nsCode); if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); }
void TrySettingElementType(XmlSchemaType schemaType, XmlQualifiedName schemaTypeName, PropertyInfo propInfo) { var guessedType = GuessXmlType(schemaTypeName); var dotNetType = GuessParsableDotNetType(guessedType); if (LooksLikeParsableSimpleType(guessedType, dotNetType)) { propInfo.XmlType = dotNetType; propInfo.IsParsable = true; } else if (schemaType != null) { propInfo.XmlType = "string"; } }
PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute) { var prop = new PropertyInfo(classInfo){XmlName = attribute.Name, XmlType = "string"}; TrySettingElementType(attribute.SchemaType, attribute.SchemaTypeName, prop); return prop; }
private void GenerateElementProperty(ClassInfo classInfo, XmlSchemaElement elem, bool isList, string nsCode) { var propInfo = new PropertyInfo(classInfo) { IsList = isList, XmlName = elem.Name, XmlType = ResolveTypeName(elem, nsCode) }; var generatedElement = GenerateElement(elem, nsCode); if (!generatedElement) TrySettingElementType(elem.SchemaType, elem.SchemaTypeName, propInfo); if (!classInfo.Elements.Contains(propInfo)) classInfo.Elements.Add(propInfo); }
private bool Equals(PropertyInfo other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.XmlName, XmlName) && Equals(other.XmlType, XmlType) && other.IsList.Equals(IsList) && Equals(other._targetClass, _targetClass); }