Class XmlAttributeReader
Metadata atributes provider. Uses XML document to describe attributes and their bindings.
public class XmlAttributeReader : IMetadataReader
- Inheritance
-
XmlAttributeReader
- Implements
- Extension Methods
Examples
XML format:
<[Root]> <Type Name="<Type.FullName|Type.Name>"> <Member Name="<Name>"> [<Attribute />]* </Member> [<Attribute />]* </Type> </[Root]>
- Root node name could be any
- Type nodes define entity classes with entity type name specified in Name attribute (must be
typeof(Entity).FullName
ortypeof(Entity).Name
value) - Member nodes define entity class members with mapping attributes with member name specified in Name attribute
- Attr nodes define attributes of entity (if nested into Type node) or entity member (when nested into Member node)
Attribute node format:
<[AttributeTypeName]> <[PropertyName] Value="<serialized_value>" Type="<Type.FullName|Type.Name>" /> </[AttributeTypeName]>
- Node name is a mapping attribute type name as
Type.FullName
,Type.Name
orType.Name
without"Attribute"
suffix - PropertyName node name is a name of attribute property you want to set
- Type attribute specify value type as
Type.FullName
orType.Name
string and specified only for non-string properties - Value contains attribute property value, serialized as string, understandable by ChangeType(object?, Type, MappingSchema?, ConversionType) method
Constructors
XmlAttributeReader(Stream)
Creates metadata provider instance.
public XmlAttributeReader(Stream xmlDocStream)
Parameters
xmlDocStream
StreamStream with XML document.
XmlAttributeReader(string)
Creates metadata provider instance.
public XmlAttributeReader(string xmlFile)
Parameters
xmlFile
stringParameter could reference to (probed in specified order):
- full or relative path to XML file resolved against current directory
- full or relative path to XML file resolved against application's app domain base directory (BaseDirectory)
- name of resource with XML document, resolved using GetManifestResourceStream(string) method
- name of resource suffix (
.{
) for resource with XML document, resolved using GetManifestResourceStream(string) methodxmlFile
}
XmlAttributeReader(string, Assembly)
Creates metadata provider instance.
public XmlAttributeReader(string xmlFile, Assembly assembly)
Parameters
xmlFile
stringParameter could reference to (probed in specified order):
- full or relative path to XML file resolved against current directory
- full or relative path to XML file resolved against application's app domain base directory (BaseDirectory)
- name of resource with XML document, resolved using GetManifestResourceStream(string) method
- name of resource suffix (
.{
) for resource with XML document, resolved using GetManifestResourceStream(string) methodxmlFile
}
assembly
AssemblyAssembly to load resource from for two last options from
xmlFile
parameter.
Methods
GetAttributes(Type)
Gets all mapping attributes on specified type.
public MappingAttribute[] GetAttributes(Type type)
Parameters
type
TypeAttributes owner type.
Returns
- MappingAttribute[]
Array of mapping attributes.
GetAttributes(Type, MemberInfo)
Gets all mapping attributes on specified type member.
public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
Parameters
type
TypeMember type. Could be used by some metadata providers to identify actual member owner type.
memberInfo
MemberInfoType member for which mapping attributes should be returned.
Returns
- MappingAttribute[]
Array of attributes.
GetDynamicColumns(Type)
Gets the dynamic columns defined on given type.
public MemberInfo[] GetDynamicColumns(Type type)
Parameters
type
TypeThe type.
Returns
- MemberInfo[]
All dynamic columns defined on given type.
GetObjectID()
Should return a unique ID for cache purposes. If the implemented Metadata reader returns instance-specific data you'll need to calculate a unique value based on content. Otherwise just use a static const e.g. $".{nameof(YourMetadataReader)}."
public string GetObjectID()
Returns
- string
The object ID as string