本文整理汇总了C#中IDictionaryAdapter类的典型用法代码示例。如果您正苦于以下问题:C# IDictionaryAdapter类的具体用法?C# IDictionaryAdapter怎么用?C# IDictionaryAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDictionaryAdapter类属于命名空间,在下文中一共展示了IDictionaryAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue
public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, object oldValue, ref object value)
{
var newNode = (XmlNode) value;
using (var writer = new XmlSubtreeWriter(node))
newNode.WriteTo(writer);
}
示例2: InvalidOperationException
void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
{
var meta = dictionaryAdapter.Meta;
if (meta.MetaInitializers.OfType<XPathBehavior>().FirstOrDefault() == null)
{
throw new InvalidOperationException(string.Format(
"Interface {0} requested xpath support, but was not configured properly. " +
"Did you forget to add an XPathBehavior?", meta.Type.FullName));
}
var xmlMeta = dictionaryAdapter.GetXmlMeta();
if (dictionaryAdapter.This.CreateStrategy == null)
{
dictionaryAdapter.This.CreateStrategy = this;
dictionaryAdapter.This.AddCopyStrategy(this);
}
if (rootXmlMeta == null)
{
rootXmlMeta = xmlMeta;
Context.ApplyBehaviors(rootXmlMeta, behaviors);
if (Parent == null)
{
foreach (var behavior in behaviors)
{
if (behavior is XPathAttribute)
{
var attrib = (XPathAttribute)behavior;
var compiledExpression = attrib.CompiledExpression;
if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
{
break;
}
var navigator = Context.SelectSingleNode(compiledExpression, root);
if (navigator != null)
{
root = navigator;
break;
}
}
}
MoveOffRoot(root, XPathNodeType.Element);
}
}
else
{
if (overlays == null)
overlays = new Dictionary<Type, XPathContext>();
XPathContext overlay;
if (overlays.TryGetValue(meta.Type, out overlay) == false)
{
overlay = new XPathContext().ApplyBehaviors(xmlMeta, behaviors);
overlays.Add(meta.Type, overlay);
}
}
}
示例3: SetValue
public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, ref object value)
{
var source = (Array) value;
var target = (Array) null;
var itemType = source.GetType().GetElementType();
var subaccessor = accessor.GetCollectionAccessor(itemType);
var cursor = subaccessor.SelectCollectionItems(node, true);
var serializer = subaccessor.Serializer;
var references = XmlAdapter.For(parent).References;
for (var i = 0; i < source.Length; i++)
{
var originalItem = source.GetValue(i);
var assignedItem = originalItem;
subaccessor.SetValue(cursor, parent, references, cursor.MoveNext(), null /* TODO: Get Value */, ref assignedItem);
if (target != null)
{
target.SetValue(assignedItem, i);
}
else if (!Equals(assignedItem, originalItem))
{
target = Array.CreateInstance(itemType, source.Length);
Array.Copy(source, target, i);
target.SetValue(assignedItem, i);
}
}
cursor.RemoveAllNext();
if (target != null)
value = target;
}
示例4: GetValue
public override object GetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor)
{
using (var reader = new XmlSubtreeReader(node, Root))
return serializer.CanDeserialize(reader)
? serializer.Deserialize(reader)
: null;
}
示例5: CopyTo
public void CopyTo(IDictionaryAdapter other, Func<PropertyDescriptor, bool> selector)
{
if (ReferenceEquals(this, other))
{
return;
}
if (other.Meta.Type.IsAssignableFrom(Meta.Type) == false)
{
throw new ArgumentException(string.Format(
"Unable to copy to {0}. The type must be assignable from {1}.",
other.Meta.Type.FullName, Meta.Type.FullName));
}
if (This.CopyStrategies.Aggregate(false, (copied, s) => copied | s.Copy(this, other, ref selector)))
{
return;
}
selector = selector ?? (property => true);
foreach (var property in This.Properties.Values.Where(property => selector(property)))
{
var propertyValue = GetProperty(property.PropertyName, true);
other.SetProperty(property.PropertyName, ref propertyValue);
}
}
示例6: GetValueCore
private object GetValueCore(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor)
{
var itemType = node.ClrType.GetGenericArguments()[0];
var listType = ListTypeConstructor.MakeGenericType(itemType);
var subaccessor = accessor.GetCollectionAccessor(itemType);
return Activator.CreateInstance(listType, node, parent, subaccessor);
}
示例7: SetValue
public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, object oldValue, ref object value)
{
if (node.ClrType != typeof(object))
XmlTypeSerializer.For(node.ClrType).SetValue(node, parent, accessor, oldValue, ref value);
else
node.Clear();
}
示例8: GetValue
public override object GetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor)
{
var source = node.AsRealizable<XmlNode>();
return (source != null && source.IsReal)
? source.Value
: null;
}
示例9: GetPropertyAsString
bool IDictionaryPropertySetter.SetPropertyValue(IDictionaryAdapter dictionaryAdapter,
string key, ref object value, PropertyDescriptor property)
{
if (value != null)
{
value = GetPropertyAsString(property, value);
}
return true;
}
示例10: GetPropertyValue
public object GetPropertyValue(IDictionaryAdapter dictionaryAdapter, string key, object storedValue, PropertyDescriptor property, bool ifExists)
{
if (storedValue != null)
{
return storedValue;
}
throw new InvalidOperationException(string.Format("App setting '{0}' not found!", key));
}
示例11: Hashtable
object IDictionaryCreateStrategy.Create(IDictionaryAdapter adapter, Type type, IDictionary dictionary)
{
dictionary = dictionary ??
#if SILVERLIGHT
new Dictionary<object, object>();
#else
new Hashtable();
#endif
return adapter.This.Factory.GetAdapter(type, dictionary, adapter.This.Descriptor); ;
}
示例12: Equals
public bool Equals(IDictionaryAdapter adapter1, IDictionaryAdapter adapter2)
{
var id1 = adapter1.GetProperty("Id", false);
if (id1 == null) return false;
var id2 = adapter2.GetProperty("Id", false);
if (id2 == null) return false;
return id1.Equals(id2);
}
示例13: GetDictionaryMeta
private static DictionaryAdapterMeta GetDictionaryMeta(IDictionaryAdapter dictionaryAdapter, Type otherType)
{
var meta = dictionaryAdapter.Meta;
if (otherType != null && otherType != meta.Type)
{
meta = dictionaryAdapter.This.Factory.GetAdapterMeta(otherType,
new DictionaryDescriptor().AddBehavior(XPathBehavior.Instance));
}
return meta;
}
示例14: ApplyValidationRules
private void ApplyValidationRules(IDictionaryAdapter dictionaryAdapter, IEnumerable<IValidationRule> rules,
PropertyDescriptor property, object propertyValue, IList<String> errors)
{
if (rules != null)
{
foreach (var rule in rules)
{
rule.Apply(dictionaryAdapter, property, propertyValue, errors);
}
}
}
示例15: GetPropertyValue
public object GetPropertyValue(IDictionaryAdapter dictionaryAdapter,
string key, object storedValue, PropertyDescriptor property, bool ifExists)
{
if (storedValue == null || storedValue.Equals(UnassignedGuid))
{
storedValue = Guid.NewGuid();
property.SetPropertyValue(dictionaryAdapter, key, ref storedValue, dictionaryAdapter.This.Descriptor);
}
return storedValue;
}