November Happy Hour will be moved to Thursday December 5th.

Class MetaObject

Stores the user meta fields of an instance of a meta class, for a single language.

Inheritance
System.Object
MetaObject
Implements
System.Runtime.Serialization.ISerializable
System.Xml.Serialization.IXmlSerializable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Mediachase.MetaDataPlus
Assembly: Mediachase.MetaDataPlus.dll
Version: 13.30.0
Syntax
public class MetaObject : ISerializable, IXmlSerializable
Remarks

Though the object is marked as serializable, the custom serialization handlers do not properly save all data. Only the meta class, object state, and field storage are saved. Any use of a meta object that has gone through the custom serialization is likely to cause issues.

Constructors

MetaObject()

Declaration
protected MetaObject()

MetaObject(MetaClass)

Creates a new meta object of the specified class.

Declaration
public MetaObject(MetaClass metaClass)
Parameters
Type Name Description
MetaClass metaClass

The type of meta object to create.

MetaObject(MetaClass, Func<MetaField, Object>)

Initializes a new instance of the MetaObject class.

Declaration
protected MetaObject(MetaClass metaClass, Func<MetaField, object> getValue)
Parameters
Type Name Description
MetaClass metaClass

The meta class.

System.Func<MetaField, System.Object> getValue

The delegate to get field values.

MetaObject(MetaClass, Int32)

Creates a new meta object of the specified class, with the specified identifier.

Declaration
public MetaObject(MetaClass metaClass, int objectId)
Parameters
Type Name Description
MetaClass metaClass

The type of meta object to create.

System.Int32 objectId

The unique identifier for the object.

MetaObject(SerializationInfo, StreamingContext)

Declaration
protected MetaObject(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
System.Runtime.Serialization.SerializationInfo info
System.Runtime.Serialization.StreamingContext context

Properties

ConnectionHandler

The connection handler.

Declaration
public Injected<IConnectionStringHandler> ConnectionHandler { get; set; }
Property Value
Type Description
EPiServer.ServiceLocation.Injected<IConnectionStringHandler>

Created

The date and time this meta object was created.

Declaration
public virtual DateTime Created { get; set; }
Property Value
Type Description
System.DateTime
Remarks

The value should be stored in UTC.

CreatorId

A key to the user who created this meta object.

Declaration
public virtual string CreatorId { get; set; }
Property Value
Type Description
System.String

DisableSync

Disable sync with content versions.

Declaration
public virtual bool DisableSync { get; set; }
Property Value
Type Description
System.Boolean

FieldStorage

A hashtable containing the meta fields of this meta object, keyed by name.

Declaration
protected Hashtable FieldStorage { get; }
Property Value
Type Description
System.Collections.Hashtable

Id

The unique identifier of the meta object.

Declaration
public int Id { get; protected set; }
Property Value
Type Description
System.Int32
Remarks

Identifiers less than or equal to zero are considered placeholders. If such an identifier is assigned, the object state will be automatically set to Added.

Item[String]

Indexes user meta field values by name.

Declaration
public virtual object this[string fieldName] { get; set; }
Parameters
Type Name Description
System.String fieldName
Property Value
Type Description
System.Object
Remarks

NOTE: Indexing the meta object by the meta field name instance will validate the value and set the object state to modified. If this is desired, use the indexer for MetaFields with a proper MetaField instance. This is only to maintain the same behavior as previous versions, and should not be interpreted as a feature.

MetaClass

The meta class that this meta object is an instance of.

Declaration
public MetaClass MetaClass { get; }
Property Value
Type Description
MetaClass

Modified

The date and time this meta object was last modified.

Declaration
public virtual DateTime Modified { get; set; }
Property Value
Type Description
System.DateTime
Remarks

The value should be stored in UTC.

ModifierId

A key to the user who last modified this meta object.

Declaration
public virtual string ModifierId { get; set; }
Property Value
Type Description
System.String

ObjectState

The state of this meta object.

Declaration
public MetaObjectState ObjectState { get; }
Property Value
Type Description
MetaObjectState

Methods

AcceptChanges(MetaDataContext)

Commits in memory changes to the database.

Declaration
public virtual void AcceptChanges(MetaDataContext context)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

Remarks

The meta object already has a meta data context nested into MetaClass.Context. While the multi-language values in this object will be for language MetaClass.Context.Language, all saves through AcceptChanges will use the supplied context, possible saving fields to a different langauge than they were loaded from. While this is known behavior, it is not necessarily a feature.

ChangeState()

Sets the object to a modified state.

Declaration
protected void ChangeState()

Clone(MetaObject)

Clones the specified meta object, copies its field storage object.

Declaration
public static MetaObject Clone(MetaObject metaObject)
Parameters
Type Name Description
MetaObject metaObject

The meta object to clone.

Returns
Type Description
MetaObject

The cloned meta object, or null if the metaObject is null.

CloneMetaFieldReferenceTypes(Hashtable, Hashtable)

Creates deep clones of any reference types in the hashtable: MetaDictionaryItem, System.Array of MetaDictionaryItem, MetaFile, MetaStringDictionary and MetaObject.

Declaration
protected void CloneMetaFieldReferenceTypes(Hashtable original, Hashtable clone)
Parameters
Type Name Description
System.Collections.Hashtable original

The original.

System.Collections.Hashtable clone

The clone.

DeepCloneImplementation()

Implements deep cloning. This base implementation handles shallow cloning of members as well as deep cloning of the meta fields accessed through the default indexer. Subclasses that define additional reference members need to override this method and implement deep cloning for those members.

Declaration
protected virtual object DeepCloneImplementation()
Returns
Type Description
System.Object

A new object that is a deep copy of the current instance.

Delete()

Marks this meta object for deletion.

Declaration
public virtual void Delete()
Remarks

The actual delete is not performed until AcceptChanges is called. Static delete methods call overrides of this method.

Delete(MetaDataContext, Int32, MetaClass)

Deletes the specified meta object.

Declaration
public static void Delete(MetaDataContext context, int objectId, MetaClass type)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to delete.

MetaClass type

The meta class of the object to load.

Delete(MetaDataContext, Int32, Int32)

Deletes the specified meta object.

Declaration
public static void Delete(MetaDataContext context, int objectId, int metaClassId)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to delete.

System.Int32 metaClassId

The id of the meta class that the object is an instance of.

Delete(MetaDataContext, Int32, String)

Deletes the specified meta object.

Declaration
public static void Delete(MetaDataContext context, int objectId, string metaClassName)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to delete.

System.String metaClassName

The name of the meta class that the object is an instance of.

DoSetMetaField(MetaField, Object, Object, Boolean, Action<String, Object>)

Declaration
protected void DoSetMetaField(MetaField metaField, object newValue, object oldValue, bool validate, Action<string, object> setValue)
Parameters
Type Name Description
MetaField metaField
System.Object newValue
System.Object oldValue
System.Boolean validate
System.Action<System.String, System.Object> setValue

GetBool(String)

Declaration
public bool GetBool(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.Boolean

GetChildElements(XDocument, String)

Gets the child elements.

Declaration
protected IEnumerable<XElement> GetChildElements(XDocument document, string elementName)
Parameters
Type Name Description
System.Xml.Linq.XDocument document

The document.

System.String elementName

Name of the element.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>

GetComplexFieldValues()

Creates and returns a copy of the field values hashtable, with only fields of complex types.

Declaration
public Hashtable GetComplexFieldValues()
Returns
Type Description
System.Collections.Hashtable

The filtered, cloned hashtable.

GetDateTime(MetaField)

Declaration
public DateTime GetDateTime(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
System.DateTime

GetDateTime(String)

Declaration
public DateTime GetDateTime(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.DateTime

GetDecimal(MetaField)

Declaration
public decimal GetDecimal(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
System.Decimal

GetDecimal(String)

Declaration
public decimal GetDecimal(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.Decimal

GetDefaultValue(MetaDataType)

Declaration
public static object GetDefaultValue(MetaDataType type)
Parameters
Type Name Description
MetaDataType type
Returns
Type Description
System.Object

GetDictionaryItem(MetaField)

Declaration
public MetaDictionaryItem GetDictionaryItem(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
MetaDictionaryItem

GetDictionaryItem(String)

Declaration
public MetaDictionaryItem GetDictionaryItem(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
MetaDictionaryItem

GetDictionaryItems(MetaField)

Declaration
public MetaDictionaryItem[] GetDictionaryItems(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
MetaDictionaryItem[]

GetDictionaryItems(String)

Declaration
public MetaDictionaryItem[] GetDictionaryItems(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
MetaDictionaryItem[]

GetElementaryFieldValues()

Creates and returns a copy of the field values hashtable, with only fields of elementary types.

Declaration
public Hashtable GetElementaryFieldValues()
Returns
Type Description
System.Collections.Hashtable

The filtered, cloned hashtable.

GetFile(MetaField)

Declaration
public MetaFile GetFile(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
MetaFile

GetFile(String)

Declaration
public MetaFile GetFile(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
MetaFile

GetGuid(MetaField)

Declaration
public Guid GetGuid(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
System.Guid

GetGuid(String)

Declaration
public Guid GetGuid(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.Guid

GetInt(String)

Declaration
public int GetInt(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.Int32

GetInt32(MetaField)

Declaration
public int GetInt32(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
System.Int32

GetInt32(String)

Declaration
public int GetInt32(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.Int32

GetList(MetaDataContext, MetaClass)

Loads all instance of the specified meta class into an array.

Declaration
public static MetaObject[] GetList(MetaDataContext context, MetaClass type)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

MetaClass type

The type of meta objects to load.

Returns
Type Description
MetaObject[]

The array of loaded objects.

Remarks

This is extremely inefficient, and probably should not be used in production code.

GetListByLanguage(MetaDataContext, MetaClass, String)

Declaration
public static MetaObject[] GetListByLanguage(MetaDataContext context, MetaClass type, string language)
Parameters
Type Name Description
MetaDataContext context
MetaClass type
System.String language
Returns
Type Description
MetaObject[]

GetMetaObject(MetaField)

Declaration
public MetaObject GetMetaObject(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
MetaObject

GetMetaObject(String)

Declaration
public MetaObject GetMetaObject(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
MetaObject

GetObjectData(SerializationInfo, StreamingContext)

Populates a System.Runtime.Serialization.SerializationInfo with the data needed to serialize the target object.

Declaration
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
System.Runtime.Serialization.SerializationInfo info

The System.Runtime.Serialization.SerializationInfo to populate with data.

System.Runtime.Serialization.StreamingContext context

The destination (see System.Runtime.Serialization.StreamingContext) for this serialization.

Exceptions
Type Condition
System.ArgumentNullException

info

GetSchema()

Gets the schema. Should always return null.

Declaration
public XmlSchema GetSchema()
Returns
Type Description
System.Xml.Schema.XmlSchema

GetString(MetaField)

Declaration
public string GetString(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
System.String

GetString(String)

Declaration
public string GetString(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
System.String

GetStringDictionary(MetaField)

Declaration
public MetaStringDictionary GetStringDictionary(MetaField field)
Parameters
Type Name Description
MetaField field
Returns
Type Description
MetaStringDictionary

GetStringDictionary(String)

Declaration
public MetaStringDictionary GetStringDictionary(string fieldName)
Parameters
Type Name Description
System.String fieldName
Returns
Type Description
MetaStringDictionary

GetValues()

Creates and returns a copy of the entire field values hashtable.

Declaration
public Hashtable GetValues()
Returns
Type Description
System.Collections.Hashtable

The cloned hashtable.

GetXDocument(XmlReader)

Gets the x document.

Declaration
protected XDocument GetXDocument(XmlReader reader)
Parameters
Type Name Description
System.Xml.XmlReader reader

The reader.

Returns
Type Description
System.Xml.Linq.XDocument

Load(MetaClass, DataRow)

Loads a meta object of the specified type from in-memory data.

Declaration
protected void Load(MetaClass type, DataRow row)
Parameters
Type Name Description
MetaClass type

he type of the meta object to load.

System.Data.DataRow row

Data describing the meta object.

Load(MetaClass, DataRowView)

Loads a meta object of the specified type from in-memory data.

Declaration
protected void Load(MetaClass type, DataRowView row)
Parameters
Type Name Description
MetaClass type

he type of the meta object to load.

System.Data.DataRowView row

Data describing the meta object.

Load(MetaClass, IDataReader)

Loads a meta object of the specified type from in-memory data.

Declaration
protected void Load(MetaClass type, IDataReader reader)
Parameters
Type Name Description
MetaClass type

The type of the meta object to load.

System.Data.IDataReader reader

Data describing the meta object.

Load(MetaDataContext, Int32, MetaClass)

Loads the specified meta object.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, MetaClass type)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to load.

MetaClass type

The meta class to load.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

Load(MetaDataContext, Int32, MetaClass, String, DateTime)

Loads the specified meta object and sets modification information.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, MetaClass type, string modifierId, DateTime modified)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to load.

MetaClass type

The meta class to load.

System.String modifierId

A key representing the user about to modify the object.

System.DateTime modified

The date and time to use as a timestamp for the pending modification.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

Load(MetaDataContext, Int32, Int32)

Loads the specified meta object.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, int metaClassId)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to load.

System.Int32 metaClassId

The unique identifier of the meta class to load.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

Load(MetaDataContext, Int32, Int32, String, DateTime)

Loads the specified meta object and sets modification information.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, int metaClassId, string modifierId, DateTime modified)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to load.

System.Int32 metaClassId

The unique identifier of the meta class to load.

System.String modifierId

A key representing the user about to modify the object.

System.DateTime modified

The date and time to use as a timestamp for the pending modification.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

Load(MetaDataContext, Int32, String)

Loads the specified meta object.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, string metaClassName)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to delete.

System.String metaClassName

The name of the meta class to load.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

Load(MetaDataContext, Int32, String, String, DateTime)

Loads the specified meta object and sets modification information.

Declaration
public static MetaObject Load(MetaDataContext context, int objectId, string metaClassName, string modifierId, DateTime modified)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

System.Int32 objectId

The unique identifier of the object to load.

System.String metaClassName

The name of the meta class to load.

System.String modifierId

A key representing the user about to modify the object.

System.DateTime modified

The date and time to use as a timestamp for the pending modification.

Returns
Type Description
MetaObject

The loaded meta object, or null if it was not found.

ReadXml(XmlReader)

Generates an object from its XML representation.

Declaration
public virtual void ReadXml(XmlReader reader)
Parameters
Type Name Description
System.Xml.XmlReader reader

The System.Xml.XmlReader stream from which the object is deserialized.

RejectChanges(MetaDataContext)

Rejects any changes, restoring the object to its original state.

Declaration
public void RejectChanges(MetaDataContext context)
Parameters
Type Name Description
MetaDataContext context

The meta data context.

SetMetaField(MetaField, Object, Boolean)

Sets the named metafield to the value. If validation is enabled, the type of the value is checked and the state of the object is updated.

Declaration
protected void SetMetaField(MetaField metaField, object value, bool validate = true)
Parameters
Type Name Description
MetaField metaField

The meta field.

System.Object value

The value to set in the field.

System.Boolean validate

If true, the value type is checked and the object state is updated.

SetMetaField(String, Object, Boolean)

Sets the named metafield to the value. If validation is enabled, the type of the value is checked and the state of the object is updated.

Declaration
public virtual void SetMetaField(string fieldName, object value, bool validate = true)
Parameters
Type Name Description
System.String fieldName

The name of the meta field to set.

System.Object value

The value to set in the field.

System.Boolean validate

If true, the value type is checked and the object state is updated.

ValidateMetaField(MetaField, Object)

Ensures that the specified value is appropriate to be stored in the specified meta field. If the value is not valid, an exception will be thrown.

Declaration
protected void ValidateMetaField(MetaField metaField, object value)
Parameters
Type Name Description
MetaField metaField

The meta field.

System.Object value

The value to check.

ValidateMetaField(String, Object)

Ensures that the specified value is appropriate to be stored in the specified meta field. If the value is not valid, an exception will be thrown.

Declaration
protected void ValidateMetaField(string metaFieldName, object value)
Parameters
Type Name Description
System.String metaFieldName

The name of the meta field.

System.Object value

The value to check.

WriteXml(XmlWriter)

Converts an object into its XML representation.

Declaration
public virtual void WriteXml(XmlWriter writer)
Parameters
Type Name Description
System.Xml.XmlWriter writer

The System.Xml.XmlWriter stream to which the object is serialized

Implements

System.Runtime.Serialization.ISerializable
System.Xml.Serialization.IXmlSerializable