本文整理汇总了C#中FieldDescriptor.ChildClassDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# FieldDescriptor.ChildClassDescriptor方法的具体用法?C# FieldDescriptor.ChildClassDescriptor怎么用?C# FieldDescriptor.ChildClassDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldDescriptor
的用法示例。
在下文中一共展示了FieldDescriptor.ChildClassDescriptor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSubRoot
/// <summary>
///
/// </summary>
/// <param name="currentFieldDescriptor"></param>
/// <param name="tagName"></param>
/// <param name="simplId"></param>
/// <returns></returns>
private object GetSubRoot(FieldDescriptor currentFieldDescriptor, string tagName, out string simplId)
{
_jsonReader.Read();
Object subRoot = null;
simplId = null;
if(_jsonReader.Value != null && _jsonReader.Value.ToString().Equals(TranslationContext.JsonSimplRef))
{
_jsonReader.Read();
simplId = _jsonReader.Value.ToString();
var referencedObject = translationContext.GetFromMap(simplId);
if (referencedObject != null)
{
subRoot = referencedObject;
}
_jsonReader.Read();
}
else
{
ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(tagName);
if (subRootClassDescriptor != null)
{
subRoot = subRootClassDescriptor.GetInstance();
if (subRoot != null)
{
DeserializationPreHook(subRoot, translationContext);
if (deserializationHookStrategy != null)
deserializationHookStrategy.DeserializationPreHook(subRoot, currentFieldDescriptor);
DeserializeObjectFields(subRoot, subRootClassDescriptor);
}
else
{
Debug.WriteLine("Skipping tag: " + tagName + ". Failed to create a new instance of " + currentFieldDescriptor.Name);
var newObject = 1;
while (_jsonReader.TokenType != JsonToken.EndObject || newObject > 0)
{
_jsonReader.Read();
if (_jsonReader.TokenType == JsonToken.StartObject)
newObject++;
else if (_jsonReader.TokenType == JsonToken.EndObject)
newObject--;
}
}
}
else
{
Debug.WriteLine("skipping tag: " + tagName + ". not assignable to " + currentFieldDescriptor.Name);
}
}
return subRoot;
}
示例2: DeserializeComposite
/// <summary>
///
/// </summary>
/// <param name="root"></param>
/// <param name="currentFieldDescriptor"></param>
private void DeserializeComposite(object root, FieldDescriptor currentFieldDescriptor)
{
//while (_jsonReader.Value == null && _jsonReader.TokenType != JsonToken.EndObject)
//_jsonReader.Read();
String tagName = (_jsonReader.Value != null) ? _jsonReader.Value.ToString() : null;
ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(tagName);
_jsonReader.Read();
if (subRootClassDescriptor != null && _jsonReader.TokenType == JsonToken.StartObject)
{
string simplId;
var subRoot = GetSubRoot(currentFieldDescriptor, tagName, out simplId);
if (subRoot != null)
currentFieldDescriptor.SetFieldToComposite(root, subRoot);
else if (simplId != null)
{
translationContext.RefObjectNeedsIdResolve(root, currentFieldDescriptor, simplId);
}
}
else
{
Debug.WriteLine("ignore tag: " + tagName + ". expected different tag while deserializing composite.");
_jsonReader.Skip();
}
}
示例3: DeserializeCompositeCollection
/// <summary>
///
/// </summary>
/// <param name="root"></param>
/// <param name="currentFieldDescriptor"></param>
private void DeserializeCompositeCollection(object root, FieldDescriptor currentFieldDescriptor)
{
// advance to StartArray token
_jsonReader.Read();
var oldFormat = HandleBackwardsCompatabilityForDoubleWrappedCollections();
int collectionCountIncludingRefs = 0;
// advance to first StartObject token
_jsonReader.Read();
while (_jsonReader.TokenType != JsonToken.EndArray)
{
var tagName = currentFieldDescriptor.CollectionOrMapTagName;
if (currentFieldDescriptor.IsPolymorphic)
{
// advance to Property token
_jsonReader.Read();
tagName = _jsonReader.Value.ToString();
ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(tagName);
if (subRootClassDescriptor == null)
{
Debug.WriteLine("skipping tag: " + tagName + ". not assignable to " + currentFieldDescriptor.Name);
_jsonReader.Skip();
_jsonReader.Read();
continue;
}
// advance past wrap tag to StartObject token
_jsonReader.Read();
}
DeserializeAndAddToCollection(root, currentFieldDescriptor, tagName, collectionCountIncludingRefs);
collectionCountIncludingRefs++;
if (currentFieldDescriptor.IsPolymorphic)
_jsonReader.Read();
_jsonReader.Read();
}
if (oldFormat)
_jsonReader.Read();
}
示例4: GetSubRoot
/// <summary>
///
/// </summary>
/// <param name="currentFieldDescriptor"></param>
/// <param name="currentTagName"></param>
/// <param name="root"> </param>
/// <returns></returns>
private object GetSubRoot(FieldDescriptor currentFieldDescriptor, string currentTagName, object root)
{
Object subRoot;
ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(currentTagName);
String simplReference;
if ((simplReference = GetSimplReference()) != null)
{
subRoot = translationContext.GetFromMap(simplReference);
if (subRoot == null)
{
Debug.WriteLine("Cannot find simpl:ref " + simplReference);
}
return subRoot;
}
if(subRootClassDescriptor == null)
{
Debug.WriteLine("ignoring element: " + currentTagName);
//_xmlReader.Skip();
return null;
}
subRoot = subRootClassDescriptor.GetInstance();
DeserializationPreHook(subRoot, translationContext);
if (deserializationHookStrategy != null)
deserializationHookStrategy.DeserializationPreHook(subRoot, currentFieldDescriptor);
if (subRoot != null)
{
if (subRoot is ElementState && root is ElementState)
{
((ElementState) subRoot).Parent = root as ElementState;
}
}
DeserializeAttributes(subRoot, subRootClassDescriptor);
if (!_xmlReader.IsEmptyElement)
{
CreateObjectModel(subRoot, subRootClassDescriptor, currentTagName);
}
else
{
DeserializationPostHook(subRoot, translationContext);
if (deserializationHookStrategy != null)
deserializationHookStrategy.DeserializationPostHook(subRoot, null);
}
return subRoot;
}