本文整理汇总了C#中CollectionDataContract类 的典型用法代码示例。如果您正苦于以下问题:C# CollectionDataContract类的具体用法?C# CollectionDataContract怎么用?C# CollectionDataContract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollectionDataContract类 属于命名空间,在下文中一共展示了CollectionDataContract类 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConvertGenericDictionaryToArray
public static List<object> ConvertGenericDictionaryToArray(DataContractJsonSerializer serializer, IEnumerable value, CollectionDataContract dataContract, XmlObjectSerializerWriteContextComplexJson context, bool writeServerType)
{
List<object> keyValuePair = new List<object>();
Dictionary<string, object> currentEntry;
Type[] declaredTypes = dataContract.ItemType.GetGenericArguments();
MethodInfo getEnumeratorMethod = dataContract.GetEnumeratorMethod;
IDictionaryEnumerator enumerator = (IDictionaryEnumerator)((getEnumeratorMethod == null) ? value.GetEnumerator() : (IDictionaryEnumerator)getEnumeratorMethod.Invoke(value, Array.Empty<Type>()));
while (enumerator.MoveNext())
{
DictionaryEntry current = enumerator.Entry;
DataContract currentDataContract = DataContract.GetDataContract(enumerator.Current.GetType());
currentEntry = new Dictionary<string, object>();
if (writeServerType)
{
AddTypeInformation(currentEntry, currentDataContract);
}
context.PushKnownTypes(dataContract);
AddDictionaryEntryData(serializer, currentEntry, writeServerType ? JsonGlobals.KeyString.ToLowerInvariant() : JsonGlobals.KeyString, declaredTypes[0], current.Key, context);
AddDictionaryEntryData(serializer, currentEntry, writeServerType ? JsonGlobals.ValueString.ToLowerInvariant() : JsonGlobals.ValueString, declaredTypes[1], current.Value, context);
keyValuePair.Add(currentEntry);
context.PopKnownTypes(dataContract);
}
return keyValuePair;
}
开发者ID:noahfalk, 项目名称:corefx, 代码行数:25, 代码来源:DataContractToObjectConverter.cs
示例2: ConvertGenericListToArray
public static IEnumerable ConvertGenericListToArray(DataContractJsonSerializer serializer, IEnumerable value, CollectionDataContract dataContract, XmlObjectSerializerWriteContextComplexJson context, bool writeServerType)
{
Type listArgumentType = dataContract.ItemType;
if (listArgumentType.GetTypeInfo().IsGenericType)
{
listArgumentType = listArgumentType.GetGenericArguments()[0];
}
List<object> serializedList = new List<object>();
MethodInfo getEnumeratorMethod = dataContract.GetEnumeratorMethod;
IEnumerator enumerator = (getEnumeratorMethod == null) ? value.GetEnumerator() : (IEnumerator)getEnumeratorMethod.Invoke(value, Array.Empty<Type>());
while (enumerator.MoveNext())
{
if (enumerator.Current == null || enumerator.Current.GetType().GetTypeInfo().IsPrimitive)
{
serializedList.Add(enumerator.Current);
}
else
{
Type currentItemType = enumerator.Current.GetType();
DataContract currentItemDataContract = DataContract.GetDataContract(currentItemType);
bool emitTypeInformation = EmitTypeInformation(dataContract.ItemContract, currentItemType);
if (writeServerType || emitTypeInformation)
{
context.CheckIfTypeNeedsVerifcation(dataContract.ItemContract, currentItemDataContract);
}
context.PushKnownTypes(dataContract);
serializedList.Add(serializer.ConvertDataContractToObject(enumerator.Current, currentItemDataContract, context, (writeServerType || emitTypeInformation), dataContract.ItemType.TypeHandle));
context.PopKnownTypes(dataContract);
}
}
return serializedList;
}
开发者ID:noahfalk, 项目名称:corefx, 代码行数:33, 代码来源:DataContractToObjectConverter.cs
示例3: WriteCollectionToJson
public void WriteCollectionToJson (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, CollectionDataContract dataContract)
{
this.writer = xmlWriter;
this.obj = obj;
this.context = context;
this.dataContract = dataContract;
InitArgs (collectionContract.UnderlyingType);
// DemandMemberAccessPermission(memberAccessFlag);
if (collectionContract.IsReadOnlyContract)
{
DataContract.ThrowInvalidDataContractException (collectionContract.SerializationExceptionMessage, null);
}
WriteCollection (collectionContract);
}
开发者ID:psni, 项目名称:mono, 代码行数:17, 代码来源:JsonFormatWriterGenerator_static.cs
示例4: GenerateGetOnlyCollectionReader
public XmlFormatGetOnlyCollectionReaderDelegate GenerateGetOnlyCollectionReader(CollectionDataContract collectionContract)
{
try
{
if (TD.DCGenReaderStartIsEnabled())
{
TD.DCGenReaderStart("GetOnlyCollection", collectionContract.UnderlyingType.FullName);
}
return helper.GenerateGetOnlyCollectionReader(collectionContract);
}
finally
{
if (TD.DCGenReaderStopIsEnabled())
{
TD.DCGenReaderStop();
}
}
}
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:19, 代码来源:XmlFormatReaderGenerator.cs
示例5: GenerateCollectionWriter
internal JsonFormatCollectionWriterDelegate GenerateCollectionWriter(CollectionDataContract collectionContract)
{
try
{
if (TD.DCJsonGenWriterStartIsEnabled())
{
TD.DCJsonGenWriterStart("Collection", collectionContract.UnderlyingType.FullName);
}
return helper.GenerateCollectionWriter(collectionContract);
}
finally
{
if (TD.DCJsonGenWriterStopIsEnabled())
{
TD.DCJsonGenWriterStop();
}
}
}
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:19, 代码来源:JsonFormatWriterGenerator.cs
示例6: GenerateCollectionReader
public JsonFormatCollectionReaderDelegate GenerateCollectionReader(CollectionDataContract collectionContract)
{
try
{
if (TD.DCJsonGenReaderStartIsEnabled())
{
TD.DCJsonGenReaderStart("Collection", collectionContract.StableName.Name);
}
return helper.GenerateCollectionReader(collectionContract);
}
finally
{
if (TD.DCJsonGenReaderStopIsEnabled())
{
TD.DCJsonGenReaderStop();
}
}
}
开发者ID:iskiselev, 项目名称:JSIL.NetFramework, 代码行数:21, 代码来源:JsonFormatReaderGenerator.cs
示例7: GenerateCollectionWriter
internal JsonFormatCollectionWriterDelegate GenerateCollectionWriter(CollectionDataContract collectionContract)
{
_ilg = new CodeGenerator();
bool memberAccessFlag = collectionContract.RequiresMemberAccessForWrite(null);
try
{
BeginMethod(_ilg, "Write" + DataContract.SanitizeTypeName(collectionContract.StableName.Name) + "ToJson", typeof(JsonFormatCollectionWriterDelegate), memberAccessFlag);
}
catch (SecurityException securityException)
{
if (memberAccessFlag)
{
collectionContract.RequiresMemberAccessForWrite(securityException);
}
else
{
throw;
}
}
InitArgs(collectionContract.UnderlyingType);
WriteCollection(collectionContract);
return (JsonFormatCollectionWriterDelegate)_ilg.EndMethod();
}
开发者ID:dotnet, 项目名称:corefx, 代码行数:23, 代码来源:JsonFormatWriterGenerator.cs
示例8: ReadGetOnlyCollection
void ReadGetOnlyCollection(CollectionDataContract collectionContract)
{
Type type = collectionContract.UnderlyingType;
Type itemType = collectionContract.ItemType;
bool isArray = (collectionContract.Kind == CollectionKind.Array);
string itemName = collectionContract.ItemName;
string itemNs = collectionContract.StableName.Namespace;
objectLocal = ilg.DeclareLocal(type, "objectDeserialized");
ilg.Load(contextArg);
ilg.LoadMember(XmlFormatGeneratorStatics.GetCollectionMemberMethod);
ilg.ConvertValue(Globals.TypeOfObject, type);
ilg.Stloc(objectLocal);
//check that items are actually going to be deserialized into the collection
IsStartElement(memberNamesArg, memberNamespacesArg);
ilg.If();
ilg.If(objectLocal, Cmp.EqualTo, null);
ilg.Call(null, XmlFormatGeneratorStatics.ThrowNullValueReturnedForGetOnlyCollectionExceptionMethod, type);
ilg.Else();
LocalBuilder size = ilg.DeclareLocal(Globals.TypeOfInt, "arraySize");
if (isArray)
{
ilg.Load(objectLocal);
ilg.Call(XmlFormatGeneratorStatics.GetArrayLengthMethod);
ilg.Stloc(size);
}
ilg.Call(contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, objectLocal);
LocalBuilder i = ilg.DeclareLocal(Globals.TypeOfInt, "i");
object forLoop = ilg.For(i, 0, Int32.MaxValue);
IsStartElement(memberNamesArg, memberNamespacesArg);
ilg.If();
ilg.Call(contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, 1);
LocalBuilder value = ReadCollectionItem(collectionContract, itemType, itemName, itemNs);
if (isArray)
{
ilg.If(size, Cmp.EqualTo, i);
ilg.Call(null, XmlFormatGeneratorStatics.ThrowArrayExceededSizeExceptionMethod, size, type);
ilg.Else();
ilg.StoreArrayElement(objectLocal, i, value);
ilg.EndIf();
}
else
StoreCollectionValue(objectLocal, value, collectionContract);
ilg.Else();
IsEndElement();
ilg.If();
ilg.Break(forLoop);
ilg.Else();
HandleUnexpectedItemInCollection(i);
ilg.EndIf();
ilg.EndIf();
ilg.EndFor();
ilg.Call(contextArg, XmlFormatGeneratorStatics.CheckEndOfArrayMethod, xmlReaderArg, size, memberNamesArg, memberNamespacesArg);
ilg.EndIf();
ilg.EndIf();
}
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:61, 代码来源:XmlFormatReaderGenerator.cs
示例9: ReadCollection
void ReadCollection(CollectionDataContract collectionContract)
{
Type type = collectionContract.UnderlyingType;
Type itemType = collectionContract.ItemType;
bool isArray = (collectionContract.Kind == CollectionKind.Array);
ConstructorInfo constructor = collectionContract.Constructor;
if (type.IsInterface)
{
switch (collectionContract.Kind)
{
case CollectionKind.GenericDictionary:
type = Globals.TypeOfDictionaryGeneric.MakeGenericType(itemType.GetGenericArguments());
constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, Globals.EmptyTypeArray, null);
break;
case CollectionKind.Dictionary:
type = Globals.TypeOfHashtable;
constructor = XmlFormatGeneratorStatics.HashtableCtor;
break;
case CollectionKind.Collection:
case CollectionKind.GenericCollection:
case CollectionKind.Enumerable:
case CollectionKind.GenericEnumerable:
case CollectionKind.List:
case CollectionKind.GenericList:
type = itemType.MakeArrayType();
isArray = true;
break;
}
}
string itemName = collectionContract.ItemName;
string itemNs = collectionContract.StableName.Namespace;
objectLocal = ilg.DeclareLocal(type, "objectDeserialized");
if (!isArray)
{
if (type.IsValueType)
{
ilg.Ldloca(objectLocal);
ilg.InitObj(type);
}
else
{
ilg.New(constructor);
ilg.Stloc(objectLocal);
ilg.Call(contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, objectLocal);
}
}
LocalBuilder size = ilg.DeclareLocal(Globals.TypeOfInt, "arraySize");
ilg.Call(contextArg, XmlFormatGeneratorStatics.GetArraySizeMethod);
ilg.Stloc(size);
LocalBuilder objectId = ilg.DeclareLocal(Globals.TypeOfString, "objectIdRead");
ilg.Call(contextArg, XmlFormatGeneratorStatics.GetObjectIdMethod);
ilg.Stloc(objectId);
bool canReadPrimitiveArray = false;
if (isArray && TryReadPrimitiveArray(type, itemType, size))
{
canReadPrimitiveArray = true;
ilg.IfNot();
}
ilg.If(size, Cmp.EqualTo, -1);
LocalBuilder growingCollection = null;
if (isArray)
{
growingCollection = ilg.DeclareLocal(type, "growingCollection");
ilg.NewArray(itemType, 32);
ilg.Stloc(growingCollection);
}
LocalBuilder i = ilg.DeclareLocal(Globals.TypeOfInt, "i");
object forLoop = ilg.For(i, 0, Int32.MaxValue);
IsStartElement(memberNamesArg, memberNamespacesArg);
ilg.If();
ilg.Call(contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, 1);
LocalBuilder value = ReadCollectionItem(collectionContract, itemType, itemName, itemNs);
if (isArray)
{
MethodInfo ensureArraySizeMethod = XmlFormatGeneratorStatics.EnsureArraySizeMethod.MakeGenericMethod(itemType);
ilg.Call(null, ensureArraySizeMethod, growingCollection, i);
ilg.Stloc(growingCollection);
ilg.StoreArrayElement(growingCollection, i, value);
}
else
StoreCollectionValue(objectLocal, value, collectionContract);
ilg.Else();
IsEndElement();
ilg.If();
ilg.Break(forLoop);
ilg.Else();
HandleUnexpectedItemInCollection(i);
ilg.EndIf();
ilg.EndIf();
ilg.EndFor();
if (isArray)
//.........这里部分代码省略.........
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:101, 代码来源:XmlFormatReaderGenerator.cs
示例10: GenerateCollectionReaderHelper
CodeGenerator GenerateCollectionReaderHelper(CollectionDataContract collectionContract, bool isGetOnlyCollection)
{
ilg = new CodeGenerator();
bool memberAccessFlag = collectionContract.RequiresMemberAccessForRead(null);
try
{
if (isGetOnlyCollection)
{
ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + "IsGetOnly", Globals.TypeOfXmlFormatGetOnlyCollectionReaderDelegate, memberAccessFlag);
}
else
{
ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + string.Empty, Globals.TypeOfXmlFormatCollectionReaderDelegate, memberAccessFlag);
}
}
catch (SecurityException securityException)
{
if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
{
collectionContract.RequiresMemberAccessForRead(securityException);
}
else
{
throw;
}
}
InitArgs();
DemandMemberAccessPermission(memberAccessFlag);
collectionContractArg = ilg.GetArg(4);
return ilg;
}
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:31, 代码来源:XmlFormatReaderGenerator.cs
示例11: ReadCollection
private void ReadCollection(CollectionDataContract collectionContract)
{
Type type = collectionContract.UnderlyingType;
Type itemType = collectionContract.ItemType;
bool isArray = (collectionContract.Kind == CollectionKind.Array);
ConstructorInfo constructor = collectionContract.Constructor;
if (type.GetTypeInfo().IsInterface)
{
switch (collectionContract.Kind)
{
case CollectionKind.GenericDictionary:
type = Globals.TypeOfDictionaryGeneric.MakeGenericType(itemType.GetGenericArguments());
constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Array.Empty<Type>());
break;
case CollectionKind.Dictionary:
type = Globals.TypeOfHashtable;
constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Array.Empty<Type>());
break;
case CollectionKind.Collection:
case CollectionKind.GenericCollection:
case CollectionKind.Enumerable:
case CollectionKind.GenericEnumerable:
case CollectionKind.List:
case CollectionKind.GenericList:
type = itemType.MakeArrayType();
isArray = true;
break;
}
}
_objectLocal = _ilg.DeclareLocal(type, "objectDeserialized");
if (!isArray)
{
if (type.GetTypeInfo().IsValueType)
{
_ilg.Ldloca(_objectLocal);
_ilg.InitObj(type);
}
else
{
_ilg.New(constructor);
_ilg.Stloc(_objectLocal);
_ilg.Call(_contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, _objectLocal);
}
}
bool canReadSimpleDictionary = collectionContract.Kind == CollectionKind.Dictionary ||
collectionContract.Kind == CollectionKind.GenericDictionary;
if (canReadSimpleDictionary)
{
_ilg.Load(_contextArg);
_ilg.LoadMember(JsonFormatGeneratorStatics.UseSimpleDictionaryFormatReadProperty);
_ilg.If();
ReadSimpleDictionary(collectionContract, itemType);
_ilg.Else();
}
LocalBuilder objectId = _ilg.DeclareLocal(Globals.TypeOfString, "objectIdRead");
_ilg.Call(_contextArg, XmlFormatGeneratorStatics.GetObjectIdMethod);
_ilg.Stloc(objectId);
bool canReadPrimitiveArray = false;
if (isArray && TryReadPrimitiveArray(itemType))
{
canReadPrimitiveArray = true;
_ilg.IfNot();
}
LocalBuilder growingCollection = null;
if (isArray)
{
growingCollection = _ilg.DeclareLocal(type, "growingCollection");
_ilg.NewArray(itemType, 32);
_ilg.Stloc(growingCollection);
}
LocalBuilder i = _ilg.DeclareLocal(Globals.TypeOfInt, "i");
object forLoop = _ilg.For(i, 0, Int32.MaxValue);
// Empty namespace
IsStartElement(_memberNamesArg, _emptyDictionaryStringArg);
_ilg.If();
_ilg.Call(_contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, 1);
LocalBuilder value = ReadCollectionItem(collectionContract, itemType);
if (isArray)
{
MethodInfo ensureArraySizeMethod = XmlFormatGeneratorStatics.EnsureArraySizeMethod.MakeGenericMethod(itemType);
_ilg.Call(null, ensureArraySizeMethod, growingCollection, i);
_ilg.Stloc(growingCollection);
_ilg.StoreArrayElement(growingCollection, i, value);
}
else
StoreCollectionValue(_objectLocal, value, collectionContract);
_ilg.Else();
IsEndElement();
_ilg.If();
_ilg.Break(forLoop);
_ilg.Else();
HandleUnexpectedItemInCollection(i);
_ilg.EndIf();
//.........这里部分代码省略.........
开发者ID:dotnet, 项目名称:corefx, 代码行数:101, 代码来源:JsonFormatReaderGenerator.cs
示例12: WriteCollection
void WriteCollection(CollectionDataContract collectionContract)
{
LocalBuilder itemName = ilg.DeclareLocal(typeof(XmlDictionaryString), "itemName");
ilg.Load(contextArg);
ilg.LoadMember(JsonFormatGeneratorStatics.CollectionItemNameProperty);
ilg.Store(itemName);
if (collectionContract.Kind == CollectionKind.Array)
{
Type itemType = collectionContract.ItemType;
LocalBuilder i = ilg.DeclareLocal(Globals.TypeOfInt, "i");
ilg.Call(contextArg, XmlFormatGeneratorStatics.IncrementArrayCountMethod, xmlWriterArg, objectLocal);
if (!TryWritePrimitiveArray(collectionContract.UnderlyingType, itemType, objectLocal, itemName))
{
WriteArrayAttribute();
ilg.For(i, 0, objectLocal);
if (!TryWritePrimitive(itemType, null /*value*/, null /*memberInfo*/, i /*arrayItemIndex*/, itemName, 0 /*nameIndex*/))
{
WriteStartElement(itemName, 0 /*nameIndex*/);
ilg.LoadArrayElement(objectLocal, i);
LocalBuilder memberValue = ilg.DeclareLocal(itemType, "memberValue");
ilg.Stloc(memberValue);
WriteValue(memberValue);
WriteEndElement();
}
ilg.EndFor();
}
}
else
{
MethodInfo incrementCollectionCountMethod = null;
switch (collectionContract.Kind)
{
case CollectionKind.Collection:
case CollectionKind.List:
case CollectionKind.Dictionary:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountMethod;
break;
case CollectionKind.GenericCollection:
case CollectionKind.GenericList:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(collectionContract.ItemType);
break;
case CollectionKind.GenericDictionary:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(Globals.TypeOfKeyValuePair.MakeGenericType(collectionContract.ItemType.GetGenericArguments()));
break;
}
if (incrementCollectionCountMethod != null)
{
ilg.Call(contextArg, incrementCollectionCountMethod, xmlWriterArg, objectLocal);
}
bool isDictionary = false, isGenericDictionary = false;
Type enumeratorType = null;
Type[] keyValueTypes = null;
if (collectionContract.Kind == CollectionKind.GenericDictionary)
{
isGenericDictionary = true;
keyValueTypes = collectionContract.ItemType.GetGenericArguments();
enumeratorType = Globals.TypeOfGenericDictionaryEnumerator.MakeGenericType(keyValueTypes);
}
else if (collectionContract.Kind == CollectionKind.Dictionary)
{
isDictionary = true;
keyValueTypes = new Type[] { Globals.TypeOfObject, Globals.TypeOfObject };
enumeratorType = Globals.TypeOfDictionaryEnumerator;
}
else
{
enumeratorType = collectionContract.GetEnumeratorMethod.ReturnType;
}
MethodInfo moveNextMethod = enumeratorType.GetMethod(Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, null, Globals.EmptyTypeArray, null);
MethodInfo getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, null, Globals.EmptyTypeArray, null);
if (moveNextMethod == null || getCurrentMethod == null)
{
if (enumeratorType.IsInterface)
{
if (moveNextMethod == null)
moveNextMethod = JsonFormatGeneratorStatics.MoveNextMethod;
if (getCurrentMethod == null)
getCurrentMethod = JsonFormatGeneratorStatics.GetCurrentMethod;
}
else
{
Type ienumeratorInterface = Globals.TypeOfIEnumerator;
CollectionKind kind = collectionContract.Kind;
if (kind == CollectionKind.GenericDictionary || kind == CollectionKind.GenericCollection || kind == CollectionKind.GenericEnumerable)
{
Type[] interfaceTypes = enumeratorType.GetInterfaces();
foreach (Type interfaceType in interfaceTypes)
{
if (interfaceType.IsGenericType
&& interfaceType.GetGenericTypeDefinition() == Globals.TypeOfIEnumeratorGeneric
&& interfaceType.GetGenericArguments()[0] == collectionContract.ItemType)
{
ienumeratorInterface = interfaceType;
break;
}
}
//.........这里部分代码省略.........
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:101, 代码来源:JsonFormatWriterGenerator.cs
示例13: StoreCollectionValue
void StoreCollectionValue(LocalBuilder collection, LocalBuilder value, CollectionDataContract collectionContract)
{
if (collectionContract.Kind == CollectionKind.GenericDictionary || collectionContract.Kind == CollectionKind.Dictionary)
{
ClassDataContract keyValuePairContract = DataContract.GetDataContract(value.LocalType) as ClassDataContract;
if (keyValuePairContract == null)
{
Fx.Assert("Failed to create contract for KeyValuePair type");
}
DataMember keyMember = keyValuePairContract.Members[0];
DataMember valueMember = keyValuePairContract.Members[1];
LocalBuilder pairKey = ilg.DeclareLocal(keyMember.MemberType, keyMember.Name);
LocalBuilder pairValue = ilg.DeclareLocal(valueMember.MemberType, valueMember.Name);
ilg.LoadAddress(value);
ilg.LoadMember(keyMember.MemberInfo);
ilg.Stloc(pairKey);
ilg.LoadAddress(value);
ilg.LoadMember(valueMember.MemberInfo);
ilg.Stloc(pairValue);
ilg.Call(collection, collectionContract.AddMethod, pairKey, pairValue);
if (collectionContract.AddMethod.ReturnType != Globals.TypeOfVoid)
ilg.Pop();
}
else
{
ilg.Call(collection, collectionContract.AddMethod, value);
if (collectionContract.AddMethod.ReturnType != Globals.TypeOfVoid)
ilg.Pop();
}
}
开发者ID:nlh774, 项目名称:DotNetReferenceSource, 代码行数:31, 代码来源:XmlFormatReaderGenerator.cs
示例14: StoreKeyValuePair
void StoreKeyValuePair(LocalBuilder collection, CollectionDataContract collectionContract, LocalBuilder pairKey, LocalBuilder pairValue)
{
ilg.Call(collection, collectionContract.AddMethod, pairKey, pairValue);
if (collectionContract.AddMethod.ReturnType != Globals.TypeOfVoid)
ilg.Pop();
}
开发者ID:iskiselev, 项目名称:JSIL.NetFramework, 代码行数:6, 代码来源:JsonFormatReaderGenerator.cs
示例15: GenerateCollectionReaderHelper
private CodeGenerator GenerateCollectionReaderHelper(CollectionDataContract collectionContract, bool isGetOnlyCollection)
{
_ilg = new CodeGenerator();
bool memberAccessFlag = collectionContract.RequiresMemberAccessForRead(null);
try
{
if (isGetOnlyCollection)
{
BeginMethod(_ilg, "Read" + DataContract.SanitizeTypeName(collectionContract.StableName.Name) + "FromJson" + "IsGetOnly", typeof(JsonFormatGetOnlyCollectionReaderDelegate), memberAccessFlag);
}
else
{
BeginMethod(_ilg, "Read" + DataContract.SanitizeTypeName(collectionContract.StableName.Name) + "FromJson", typeof(JsonFormatCollectionReaderDelegate), memberAccessFlag);
}
}
catch (SecurityException securityException)
{
if (memberAccessFlag)
{
collectionContract.RequiresMemberAccessForRead(securityException);
}
else
{
throw;
}
}
InitArgs();
_collectionContractArg = _ilg.GetArg(4);
return _ilg;
}
开发者ID:dotnet, 项目名称:corefx, 代码行数:30, 代码来源:JsonFormatReaderGenerator.cs
示例16: JsonFormatWriterInterpreter
public JsonFormatWriterInterpreter (CollectionDataContract collectionContract)
{
this.collectionContract = collectionContract;
}
开发者ID:psni, 项目名称:mono, 代码行数:4, 代码来源:JsonFormatWriterGenerator_static.cs
示例17: GenerateCollectionWriter
internal JsonFormatCollectionWriterDelegate GenerateCollectionWriter(CollectionDataContract collectionContract)
{
return (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, CollectionDataContract dataContract) => new JsonFormatWriterInterpreter (collectionContract).WriteCollectionToJson (xmlWriter, obj, context, dataContract);
}
开发者ID:psni, 项目名称:mono, 代码行数:4, 代码来源:JsonFormatWriterGenerator_static.cs
示例18: WriteCollection
void WriteCollection(CollectionDataContract collectionContract)
{
XmlDictionaryString itemName = context.CollectionItemName;
if (collectionContract.Kind == CollectionKind.Array)
{
Type itemType = collectionContract.ItemType;
int i;
// This check does not exist in the original dynamic code,
// but there is no other way to check type mismatch.
// CollectionSerialization.ArrayContract() shows that it is required.
if (objLocal.GetType ().GetElementType () != itemType)
throw new InvalidCastException (string.Format ("Cannot cast array of {0} to array of {1}", objLocal.GetType ().GetElementType (), itemType));
context.IncrementArrayCount (writer, (Array) objLocal);
if (!TryWritePrimitiveArray(collectionContract.UnderlyingType, itemType, () => objLocal, itemName))
{
WriteArrayAttribute ();
var arr = (Array) objLocal;
var idx = new int [1];
for (i = 0; i < arr.Length; i++) {
if (!TryWritePrimitive(itemType, null, null, i, itemName, 0)) {
WriteStartElement (itemName, 0);
idx [0] = i;
var mbrVal = arr.GetValue (idx);
WriteValue (itemType, mbrVal);
WriteEndElement ();
}
}
}
}
else
{
// This check does not exist in the original dynamic code,
// but there is no other way to check type mismatch.
// CollectionSerialization.ArrayContract() shows that it is required.
if (!collectionContract.UnderlyingType.IsAssignableFrom (objLocal.GetType ()))
throw new InvalidCastException (string.Format ("Cannot cast {0} to {1}", objLocal.GetType (), collectionContract.UnderlyingType));
MethodInfo incrementCollectionCountMethod = null;
switch (collectionContract.Kind)
{
case CollectionKind.Collection:
case CollectionKind.List:
case CollectionKind.Dictionary:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountMethod;
break;
case CollectionKind.GenericCollection:
case CollectionKind.GenericList:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(collectionContract.ItemType);
break;
case CollectionKind.GenericDictionary:
incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(Globals.TypeOfKeyValuePair.MakeGenericType(collectionContract.ItemType.GetGenericArguments()));
break;
}
if (incrementCollectionCountMethod != null)
incrementCollectionCountMethod.Invoke (context, new object [] {writer, objLocal});
bool isDictionary = false, isGenericDictionary = false;
Type enumeratorType = null;
Type [] keyValueTypes = null;
if (collectionContract.Kind == CollectionKind.GenericDictionary)
{
isGenericDictionary = true;
keyValueTypes = collectionContract.ItemType.GetGenericArguments ();
enumeratorType = Globals.TypeOfGenericDictionaryEnumerator.MakeGenericType (keyValueTypes);
}
else if (collectionContract.Kind == CollectionKind.Dictionary)
{
isDictionary = true;
keyValueTypes = new Type[] { Globals.TypeOfObject, Globals.TypeOfObject };
enumeratorType = Globals.TypeOfDictionaryEnumerator;
}
else
{
enumeratorType = collectionContract.GetEnumeratorMethod.ReturnType;
}
MethodInfo moveNextMethod = enumeratorType.GetMethod (Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, null, Globals.EmptyTypeArray, null);
MethodInfo getCurrentMethod = enumeratorType.GetMethod (Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, null, Globals.EmptyTypeArray, null);
if (moveNextMethod == null || getCurrentMethod == null)
{
if (enumeratorType.IsInterface)
{
if (moveNextMethod == null)
moveNextMethod = JsonFormatGeneratorStatics.MoveNextMethod;
if (getCurrentMethod == null)
getCurrentMethod = JsonFormatGeneratorStatics.GetCurrentMethod;
}
else
{
Type ienumeratorInterface = Globals.TypeOfIEnumerator;
CollectionKind kind = collectionContract.Kind;
if (kind == CollectionKind.GenericDictionary || kind == CollectionKind.GenericCollection || kind == CollectionKind.GenericEnumerable)
{
Type[] interfaceTypes = enumeratorType.GetInterfaces();
foreach (Type interfaceType in interfaceTypes)
{
if (interfaceType.IsGenericType
//.........这里部分代码省略.........
开发者ID:psni, 项目名称:mono, 代码行数:101, 代码来源:JsonFormatWriterGenerator_static.cs
示例19: ReadCollectionItem
private LocalBuilder ReadCollectionItem(CollectionDataContract collectionContract, Type itemType)
{
if (collectionContract.Kind == CollectionKind.Dictionary || collectionContract.Kind == CollectionKind.GenericDictionary)
{
_ilg.Call(_contextArg, XmlFormatGeneratorStatics.ResetAttributesMethod);
LocalBuilder value = _ilg.DeclareLocal(itemType, "valueRead");
_ilg.Load(_collectionContractArg);
_ilg.Call(JsonFormatGeneratorStatics.GetItemContractMethod);
_ilg.Call(JsonFormatGeneratorStatics.GetRevisedItemContractMethod);
_ilg.Load(_xmlReaderArg);
_ilg.Load(_contextArg);
_ilg.Call(JsonFormatGeneratorStatics.ReadJsonValueMethod);
_ilg.ConvertValue(Globals.TypeOfObject, itemType);
_ilg.Stloc(value);
return value;
}
else
{
return ReadValue(itemType, JsonGlobals.itemString);
}
}
开发者ID:dotnet, 项目名称:corefx, 代码行数:21, 代码来源:JsonFormatReaderGenerator.cs
示例20: ReadGetOnlyCollection
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:19192| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9988| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8327| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8696| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8639| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9657| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8624| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7998| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8656| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7535| 2022-11-06
请发表评论