Inversion
, projects notes
An implementation of [Inversion.Collections.IDataCollection1](T-Inversion.Collections.IDataCollection
1) that is safe for concurrent use.
T
: The type of the elements in the collection.
Represents a collection of Inversion.IData objects, that can be accessed by index.
T
: The type of elements in the list.
Base interface for data models in Inversion.
While this represents a point of extensibility for data models in Inversion this is pretty much limited to simple serialisation. IData
had more relevance in Acumen pre-extension methods, now it's primary untility is simply to flag what is data-model and to be able to contrain based upon that.
This approach to model serialisation is simple, but also fast, uncluttered, and explicit. The writers used obviously are often used by a whole object graph being written out, and is part of a broader application concern. The writer should not be used in any way that yields side-effects beyond the serialisation at hand. Inversion.IData.ToXml-System.Xml.XmlWriter and Inversion.IData.ToJson-Newtonsoft.Json.JsonWriter need to be fast and reliable.
Inversion favours an application where XML (or JSON for apps with data clients) is its primary external interface, which is transformed (normally with XSL) into a view stuitable for a particular class of user-agent. Other approaches may have a different regard for a data-model and IData
serves as a point of extension in those cases perhaps.
Extension methods are provided in Inversion.DataEx to provide IData.ToXml()
and IData.ToJson()
.
Produces an xml representation of the model.
writer
: The writer to used to write the xml to.
Produces a json respresentation of the model.
writer
: The writer to use for producing json.
Provides an abstract representation of the objects data expressed as a JSON object.
Adds an item to the collection.
item
: The item to add to the collection.
The label that should be used for the collection in any notation presenting the collection.
Instantiates a new empty collection with the lable provided.
label
: The label of the collection.
Instantiates an empty collection.
:Inversion.Collections.ConcurrentDataCollection{T1}.#ctor(System.Collections.Generic.IEnumerable{{T0}})
Instanciates a new data collection with elements copied from the provided collection.
collection
: The collection whose elements are copied into the new data collection.
:Inversion.Collections.ConcurrentDataCollection{T1}.#ctor(Inversion.Collections.IDataCollection{{T0}})
Instantiates a collection populating it with the elements of the provided collection.
other
: The other collection to populate the new collection with.
Creates a new instance of a data collection as a copy of this data collection.
returns:
Produces an XML representation of the collections elements to a provided writer.
writer
: The System.Xml.XmlWriter the representation is written to.
Produces an JSON representation of the collection to a provided writer.
writer
: The Newtonsoft.Json.JsonWriter the representation is written to.
Produces an XML representation of the collection to a provided writer.
writer
: The System.Xml.XmlWriter the representation is written to.
Produces an JSON representation of the collection to a provided writer.
writer
: The Newtonsoft.Json.JsonWriter the representation is written to.
The label that should be used for the collection in any notation presenting the collection.
This will default to "list".
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is created each time it is accessed.
A thread-safe dictionary of key-value pairs where the key is a string and the dictionary itself implements IData
TValue
: The type of the element values.
Represents a generic dictionary that implements Inversion.IData , where the keys are strings.
T
: The type of the element values.
.Import(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,{T0}}})
Import the provided key/value pairs into the dictionary.
other
: The key/value pairs to copy.
returns: This dictionary.
Instantiates a new empty dictionary.
:Inversion.Collections.ConcurrentDataDictionary{T1}.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,{T0}}})
Instantiates a new dictionary populated with the enumerable of key-value pairs provided.
other
: The key-value pairs to populate the dictionary with.
:Inversion.Collections.ConcurrentDataDictionary{T1}.#ctor(Inversion.Collections.DataDictionary{{T0}})
Instantiates a new dictionary populated from the dictionary provided.
other
: The other dictionary to populate this dictionary from.
Clones the dictionary.
returns: Returnes a new dictionary instance populated by this one.
:Inversion.Collections.ConcurrentDataDictionary{T1}.Import(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,{T0}}})
Imports the key-value pairs from a provided dictionary into this one.
other
: The other dictionary to import into this one.
returns: Returns the current instance of this dictionary.
Produces an XML representation of the dictionary elements.
writer
: The xml writer the xml should be written to.
Produces and xml representation of the dictionary.
writer
: The xml writer the xml should be written to.
Produces a json representation of the dictionary elements.
writer
: The json writer the json should be written to.
Produces a json representation of the dictionary.
writer
: The json writer the json should be written to.
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is created each time it is accessed.
Provides indexed acccess tot he dictionary with the key provided.
key
: The key used to index a key/value pair.
returns: Returns the value associated with the specified key.
An implementation of [Inversion.Collections.IDataCollection1](T-Inversion.Collections.IDataCollection
1) as a simple [System.Collections.Generic.List1](T-System.Collections.Generic.List
1) .
T
: The type of elements in the list.
Instantiates a new empty collection with the lable provided.
label
: The label of the collection.
Instantiates a new, empty data collection.
Instantiates a new data collection with elements copied from the provided collection.
collection
: The collection whose elements are copied into the new data collection.
Instantiates a collection populating it with the elements of the provided collection.
other
: The other collection to populate the new collection with.
Creates a clone of the collection by instantiating a new collection populated with the elements of this one.
returns: Returns a new collection populated by this one.
Produces an XML representation of the dictionaries elements, to a provided writer.
writer
: The System.Xml.XmlWriter the representation is written to.
Produces an JSON representation of the dictionaries elements, to a provided writer.
writer
: The Newtonsoft.Json.JsonWriter the representation is written to.
Produces an XML representation of the dictionaries to a provided writer.
writer
: The System.Xml.XmlWriter the representation is written to.
Produces an JSON representation of the dictionaries to a provided writer.
writer
: The Newtonsoft.Json.JsonWriter the representation is written to.
The label that should be used for the collection in any notation presenting the collection.
This will default to "list".
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is created each time it is accessed.
A collection of key/value pairs, where the key is a string.
TValue
: The type of the element values.
Instantiates a new empty instance of the dictionary.
instantiates a new dictionary with the elements copied over from the dictionary provided.
other
: The dictionary to copy elements from.
.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,{T0}}})
instantiates a new dictionary with the elements copied from iterating over the key/value pairs provided.
other
: The key/value pairs to copy.
Clones the data dictionary by instantiating a new one populated by the elemens of this one.
returns:
.Import(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,{T0}}})
Instantiates a dictionary populating it with the elements of the provided dictionary.
other
: The other dictionary to populate the new collection with.
Produces an xml representation of the elements of the dictionary.
writer
: The xml writer the representation should be written to.
Produces and xml representation of the dictionary.
writer
: The xml writer the xml should be written to.
Produces a json representation of the dictionaries elements.
writer
: The json writer the representation should be written to.
Produces a json representation of the dictionary.
writer
: The json writer the representation should be written to.
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is created each time it is accessed.
A System.Dynamic.DynamicObject implementing an [Inversion.Collections.IDataDictionary1](T-Inversion.Collections.IDataDictionary
1) .
This class is intended to help with exposing models to Razor templates, as it allows ad hoc properties to be used as dictionary keys, model.UserDetails.Name
rather than model["UserDetails"].Name
The initial idea was for the ControlState
to be one of these. When I start playing about with Razor a bit more I'll test it to see if there's any consequences.
Implements trying to set a member of the data model ensuring that the value being assigned is both of type IData
and not null.
binder
: The binder provided by the call site.value
: The value to set.
returns: true if the operation is complete, false if the call site should determine behavior.
Implements trying to get a member.
binder
: The binder provided by the call site.result
: The result of the get operation.
returns: true if the operation is complete, false if the call site should determine behavior.
.Import(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,Inversion.IData}})
Imports the key-value pairs from a provided dictionary into this one.
other
: The other dictionary to import into this one.
returns: Returns the current instance of this dictionary.
Adds the provided value to the model against the specified key.
key
: The key for the new element.value
: The value to be added/
Determines whether or not the model contains anything stored against the provided key.
key
: The key to check.
returns: Returns true if the model contains a key-value pair with a key corresponding to the specified key; otherwise returns false.
Removes the key-value pair of the specified key.
key
: The key to remove from the model.
returns: Rreturns true if the key was found and removed; otherwise returns false.
Tries to get the value of the key-value pair with the same key as the one provided.
key
: The key to lookup.value
: The value of the found key-value pair.
returns: Returns true if the operation was successful; otherwise returns false.
Adds an element to the collection.
item
: The item to add to the collection.
Removes all elements from the collection.
Checks to see if the collection contains a particular element.
item
: The item to check for in the collection.
returns: Returns true if the item is contained in the collection; otherwise returns false.
Copies elements from the collection to and array, starting at a specified index in the array.
array
: The array to copy elements to.arrayIndex
: The index in the array to start copying to.
Removes a specific item from the collection if it is present.
item
: The item to remove from the collection.
returns: Returns true if the item was removed; otherwise returns false.
Gets an enumerator that can be used to iterate over the collection.
returns: The enumerator for the collection.
Gets an enumerator that can be used to iterate over the collection.
returns: The enumerator for the collection.
Produces an xml representation of the collection.
writer
: The xml writer the xml should be written to.
Produces a json representation of the collection.
writer
: The writer the json should be written to.
Clones this collection by creating a new one populated by elements from this on.
returns: Returns the new collection as a copy of this one.
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is created each time it is accessed.
A collection of all the keys contained in the model.
A collection of all the values of the model.
Obtains the value of the key-value pair with the same key as the one provided.
key
: The key to lookup.
returns: Returns the value of the key-value pair found, if any.
Obtains the number of elements in the collection.
Determines if the collection is read-only or not.
Extension methods for Inversion.IData largely concerned with supporting both .ToXml(...)
and .ToJson(...)
Generates an XML representation of the specified Inversion.IData object.
self
: The data model to produce XML for.
returns:
Returns the XML representation as a string
.
This is implemented by creating a StringWriter
and calling .ToXml(IData, StringWriter)
Produces an xml representation of the subject IData
object.
self
: TheIData
object to act upon.writer
: The xml writer to write the representation to.
Produces a json representation of the subject IData
object.
self
: TheIData
object to act upon.
returns:
Return the json representation of the IData
object as a string.
Produces a json representation of the subject IData
object.
self
: TheIData
object to act upon.writer
: The text writer the representation should be writtern to.
Provides a JSON Object view of the objects data.
self
: TheIData
object to act upon.
returns:
Returns a JObject
representation of this objects data.
Represents a frozen view of an IData
object.
The idea here is that if you need to be using the JSON representation of a mutable entity, it's going to be expensive to generate that JSON representation each time it is accessed. This applies to XML also, but the case is felt to be more likely with the JSON rep. So the purpose of the data-view is to take a snap-shot of the entity, with the JSON being generated only the once. Unfortunately JObject
is muttable making it unfit for what is supposed to be an immutable view. A guard has been put in to throw an exception on property change for the JObject, but this is felt to be only just adequate long-term. I'm going to see how this plays out in actual usage before deciding if it's appropriate. See JDataObject
for an alternative but similar approach.
Instantiates a new data view object.
other
: TheIData
the data view should be created from.
Creates a new object that is a copy of the current instance.
returns: A new object that is a copy of this instance.
Creates a new object that is a copy of the current instance.
returns: A new object that is a copy of this instance.
Produces an xml representation of the model.
writer
: The writer to used to write the xml to.
Produces a json respresentation of the model.
writer
: The writer to use for producing json.
Provides an abstract representation of the objects data expressed as a JSON object.
An extension class providing extensions for arrays.
A simple extension that constructs a new array from one provided by calling .Clone()
on each element of the provided array.
T
: The type of the array elements.
self
: The array to act upon.
returns: Provides a new array with elements cloned from the originating array.
Utility extension methods provided for dictionaries.
.Import
{T2}(System.Collections.Generic.IDictionary{{T0},
{T1}},System.Collections.Generic.IDictionary{{T0},
{T1}})`
Copies the elements from one dictionary to another.
TKey
: The type of the dictionary keys.
TValue
: The type of the dictionary values.
self
: The dictionary being acted on.other
: The dictionary being copied from.
.ContentToXml(System.Collections.Generic.IDictionary{System.String,Inversion.IData},System.Xml.XmlWriter)
Produces an XML representation of the elements of a dictionary.
self
: The dictionary being acted upon.writer
: The System.Xml.XmlWriter the representation is written to.
An extension class providing extensions for IEnumerable{T}
objects.
Produces an XML representation of an enumerable by iterating over the elements of the enumerable and calling .ToXml()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.label
: The label of the enclosing element.
returns: An XML representation of the provided enumerable.
Produces an XML representation of an enumerable by iterating over the elements of the enumerable and calling .ToXml()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.writer
: The text writer the XML should be written to.label
: The label of the enclosing element.
Produces an XML representation of an enumerable by iterating over the elements of the enumerable and calling .ToXml()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.xml
: The xml writer the XML should be written to.label
: The label of the enclosing element.
Produces a JSON representation of an enumerable by iterating over the elements of the enumerable and calling .ToJson()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.
returns: An JSON representation of the provided enumerable.
Produces a JSON representation of an enumerable by iterating over the elements of the enumerable and calling .ToJson()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.writer
: The text writer the JSON should be written to.
Produces a JSON representation of an enumerable by iterating over the elements of the enumerable and calling .ToJson()
on them.
T
: The type of elements in the enumerable.
self
: The enumerable to act upon.json
: The json writer the JSON should be written to.
Produces a hash from all the string elements of an enumerable.
self
: The enumerable of strings to act upon.
returns: Returns a has of all the elements.
Conventient extension methods for the json writer.
Writes both a json property name, and a value at the same time.
self
: The json writer to act upon.name
: The name of the property.value
: The value of the property.
Utility extension methods provided for lists.
Just some methods to allow a list to be treated as a stack. If a stack is being used as a context in tree processing, sometimes being able to peek at more than the last element, or also treat the stack like a list is useful.
Pushes an elelent onto the list as if it were a stack.
T
: The type of the list elements.
self
: The list being acted on.item
: The element being pushed onto the list.
returns: The list being acted on.
Pops an element from the list as if it were a stack.
T
: The type of the list elements.
self
: The list being acted on.
returns: The element that was poped.
Provides an index of the list in reverse order, with list.Peek(0)
considering the last element of the list, and list.Peek(1)
being the penultimate element of the list. No bounds checking is provided.
T
: The type of the list elements.
self
: The list being acted on.i
: The index of the peek.
returns: The element found at the index.
Takes a look at the last element of a list without removing it, as if it were a stack.
T
: The type of the list elements.
self
: The list being acted on.
returns: The last element of the list.
Some utility extension methods provided for string builders.
Filters a StringBuilder
, removing any elements that the provided predicate returns true for.
self
: The string builder being acted upon.test
: The predicate to test each element for removal.
returns: The string builder being acted upon.
Removes all non-numeric characters from the string builder.
self
: The string builder being acted upon.
returns: The string builder being acted upon.
Removes all the non-alphabetic characters from the string builder.
self
: The string builder being acted upon.
returns: The string builder being acted upon.
Removes all non-alphanumeric characters from the string builder.
self
: The string builder being acted upon.
returns: The string builder being acted upon.
Removes all whitespace from the string builder.
self
: The string builder being acted upon.
returns: The string builder being acted upon.
Removes a specified number of characters from the left-side of the string builder.
self
: The string builder being acted upon.amount
:
returns: The string builder being acted upon.
Removes a specified number of characters from the right-side of the string builder.
self
: The string builder being acted upon.amount
:
returns: The string builder being acted upon.
Removes a specified number of characters from each end of the string builder.
self
: The string builder being acted upon.amount
:
returns: The string builder being acted upon.
An extension class providing extensions for string.
Determines if the string is not null and has a length greater than zero.
self
: The subject of extension.
returns: Returns true if the string has a values; otherwise returns false.
Checks if a string has a value and if not throws an System.ArgumentNullException .
self
: The subject of extension.message
: The message to use as part of the exception. Inversion.Extensions.StringEx.HasValue-System.String
Places the
self
:number
:character
:
returns:
Determines if a string is a valid XML tag name.
self
: The subject of extension.
returns: Returns true if the string is a valid XML name; otherwise, returns false.
Filters out characters from string by testing them with a predicate.
self
: The string to act upon.test
: The predicate to test each character with.
returns: Returns a new string containing only those charcters for which the test returned true.
Produces a new string by removing all non-numeric characters from the sting provided.
self
: The string to act upon.
returns: The new filtered string.
Produces a new string by removing all alphabetic characters from the sting provided.
self
: The string to act upon.
returns: The new filtered string.
Produces a new string by removing all non-alpha-numeric characters from the sting provided.
self
: The string to act upon.
returns: The new filtered string.
Produces a new string by removing all whitespace characters from the sting provided.
self
: The string to act upon.
returns: The new filtered string.
This method ensures that the returned string has only valid XML unicode charcters as specified in the XML 1.0 standard. For reference please see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char for the standard reference.
self
: The string being acted upon.
returns: A copy of the input string with non-valid charcters removed.
Removes characters from the left side of a string.
self
: The string to be acted upon.amount
: The number of charcters to remove.
returns: Returns a new string with the characters removed.
Removes characters from the right side of a string.
self
: The string to be acted upon.amount
: The number of charcters to remove.
returns: Returns a new string with the characters removed.
Removes characters from the left and right sides of a string.
self
: The string to be acted upon.amount
: The number of charcters to remove.
returns: Returns a new string with the characters removed.
Generates a simple hash for a string.
This hash is not asserted to be fit for any particular purpose other than simple features where you just need a hash of a string.
self
: The string to be acted upon.
returns: Returns a simple hash of a string.
Regards all occurrences of substrings starting and finishing with |
pipe charcters as potential keys, and if those keys occur within the provided dictionary, replaces those keys in the provided text with the corresposponding value in the dictionary.
This is performed as a single scan of characters and should be used in preference in those situations where you find yourself doing multiple replacements on a large string, as this will do them in one go.
text
: The text to act upon.kv
: The dictionary of key-value pairs for substitution.
returns: Returns a new string with any matching keys replaced.
Expresses a type that is able to consume both json and xml representations of itself.
TBuilder
: The type of the builder being used for this type.
TConcrete
: The type of the concrete product of consuming data.
Assigns values to this object based on those of the other object provided.
other
: The other object from which to take values.
returns: Returns a builder populated from the provided concrete object.
Assigns values to this object based on those in the json provided.
json
: The property set from which to take values.
returns: Returns a builded populated from the json provided.
Produced a concrete object from this one.
returns: Returns a concrete object from this one.
Describes a type that manages mutation via a Mutate
function using a builder object as an intermediary on which to exercise mutation.
TBuilder
: The type of the builder that will be used for mutation.
TConcrete
: The type of the concrete object to be created.
Mutates the current object by transforming it to a builder, applying a mutation function to the builder, and then transforming the builder back to a specified concrete type.
mutator
: The mutation function to apply to the builder.
returns: Returns a concrete object which is the product of a builder that has had the mutation function applied to it.
Implements a JObject
as an IData
type.
This is addressing a concern not disimilar to that being addressed by DataView
which is the presentation of data in abstract terms especially for views or ad-hoc data.
Instantiates a new JDataObject
from an other JObject
.
other
: TheJObject
to copy data from.
Instantiates a new JDataObject
from another IDataObject
.
other
: TheIData
object to copy data from.
Produces an xml representation of the model.
writer
: The writer to used to write the xml to.
Produces a json respresentation of the model.
writer
: The writer to use for producing json.
Provides an abstract representation of the objects data expressed as a JSON object.
An implementation of Inversion.IData that represents a simple text node within a model.
Implicitly casts a string of text into a TextData
object, by instantiating a TextData
object from the string.
text
: The string of text to be cast.
returns:
Returns the TextData
object created.
Implicitly casts a TextData
object into a string.
text
: TheTextData
object to cast.
returns:
Returns the string value of the TextData
object.
Instantiates a new TextData
object with the value of the text provided.
text
: The text to initialise from.
Instantiates a new TextData
object as a copy of the one provided.
text
: TheTextData
to copy.
Creates a new instance as a copy of the original.
returns:
A copy as a TextData
object.
Produces an xml representation of the text data.
writer
: The xml writer the representation should be written to.
Produces a json representation of the text data.
writer
: The json writer the representation should be written to.
Returns a string that represents the current object.
returns: A string that represents the current object.
The string value of the text data.
Provides an abstract representation of the objects data expressed as a JSON object.
For this type the json object is only created the once.