예제 #1
0
 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;
 }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
 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);
 }
예제 #7
0
        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);
        }
예제 #8
0
 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));
 }
예제 #9
0
 private PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute)
 {
     var prop = new PropertyInfo(classInfo)
     {
         XmlName = attribute.Name,
         XmlType = ResolveSimpleTypeName(attribute.SchemaTypeName.Name)
     };
     return prop;
 }
예제 #10
0
        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);
        }
예제 #11
0
        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";
            }
        }
예제 #12
0
 PropertyInfo PropertyFromAttribute(ClassInfo classInfo, XmlSchemaAttribute attribute)
 {
     var prop = new PropertyInfo(classInfo){XmlName = attribute.Name, XmlType = "string"};
     TrySettingElementType(attribute.SchemaType, attribute.SchemaTypeName, prop);
     return prop;
 }
예제 #13
0
        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);
        }
예제 #14
0
 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);
 }