本文整理匯總了C#中ProtoBuf.Meta.TypeModel.MapType方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeModel.MapType方法的具體用法?C# TypeModel.MapType怎麽用?C# TypeModel.MapType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ProtoBuf.Meta.TypeModel
的用法示例。
在下文中一共展示了TypeModel.MapType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TryCreate
public static ParseableSerializer TryCreate(Type type, TypeModel model)
{
if (type == null) throw new ArgumentNullException("type");
#if WINRT || PORTABLE || COREFX
MethodInfo method = null;
#if WINRT || COREFX
foreach (MethodInfo tmp in type.GetTypeInfo().GetDeclaredMethods("Parse"))
#else
foreach (MethodInfo tmp in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
#endif
{
ParameterInfo[] p;
if (tmp.Name == "Parse" && tmp.IsPublic && tmp.IsStatic && tmp.DeclaringType == type && (p = tmp.GetParameters()) != null && p.Length == 1 && p[0].ParameterType == typeof(string))
{
method = tmp;
break;
}
}
#else
MethodInfo method = type.GetMethod("Parse",
BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly,
null, new Type[] { model.MapType(typeof(string)) }, null);
#endif
if (method != null && method.ReturnType == type)
{
if (Helpers.IsValueType(type))
{
MethodInfo toString = GetCustomToString(type);
if (toString == null || toString.ReturnType != model.MapType(typeof(string))) return null; // need custom ToString, fools
}
return new ParseableSerializer(method);
}
return null;
}
示例2: CheckCallbackParameters
internal static bool CheckCallbackParameters(TypeModel model, MethodInfo method)
{
ParameterInfo[] args = method.GetParameters();
for (int i = 0; i < args.Length; i++)
{
Type paramType = args[i].ParameterType;
if(paramType == model.MapType(typeof(SerializationContext))) {}
else if(paramType == model.MapType(typeof(System.Type))) {}
#if PLAT_BINARYFORMATTER
else if(paramType == model.MapType(typeof(System.Runtime.Serialization.StreamingContext))) {}
#endif
else return false;
}
return true;
}
示例3: Create
public static AttributeMap[] Create(TypeModel model, Assembly assembly)
{
#if FEAT_IKVM
const bool inherit = false;
System.Collections.Generic.IList<CustomAttributeData> all = assembly.__GetCustomAttributes(model.MapType(typeof(Attribute)), inherit);
AttributeMap[] result = new AttributeMap[all.Count];
int index = 0;
foreach (CustomAttributeData attrib in all)
{
result[index++] = new AttributeDataMap(attrib);
}
return result;
#else
#if WINRT || COREFX
Attribute[] all = System.Linq.Enumerable.ToArray(assembly.GetCustomAttributes());
#else
const bool inherit = false;
object[] all = assembly.GetCustomAttributes(inherit);
#endif
AttributeMap[] result = new AttributeMap[all.Length];
for(int i = 0 ; i < all.Length ; i++)
{
result[i] = new ReflectionAttributeMap((Attribute)all[i]);
}
return result;
#endif
}
示例4: ArrayDecorator
public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
: base(tail)
{
Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
this.itemType = arrayType.GetElementType();
#if NO_GENERICS
Type underlyingItemType = itemType;
#else
Type underlyingItemType = supportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType);
#endif
Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType, "invalid tail");
Helpers.DebugAssert(Tail.ExpectedType != model.MapType(typeof(byte)), "Should have used BlobSerializer");
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked) options |= OPTIONS_WritePacked;
if (overwriteList) options |= OPTIONS_OverwriteList;
if (supportNull) options |= OPTIONS_SupportNull;
this.arrayType = arrayType;
}
示例5: NetObjectSerializer
public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options)
{
bool dynamicType = (options & BclHelpers.NetObjectOptions.DynamicType) != 0;
this.key = dynamicType ? -1 : key;
this.type = dynamicType ? model.MapType(typeof (object)) : type;
this.options = options;
}
示例6: NetObjectSerializer
public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options)
{
bool flag = (byte)(options & BclHelpers.NetObjectOptions.DynamicType) != 0;
this.key = ((!flag) ? key : -1);
this.type = ((!flag) ? type : model.MapType(typeof(object)));
this.options = options;
}
示例7: Create
public static AttributeMap[] Create(TypeModel model, MemberInfo member, bool inherit)
{
#if FEAT_IKVM
System.Collections.Generic.IList<CustomAttributeData> all = member.__GetCustomAttributes(model.MapType(typeof(Attribute)), inherit);
AttributeMap[] result = new AttributeMap[all.Count];
int index = 0;
foreach (CustomAttributeData attrib in all)
{
result[index++] = new AttributeDataMap(attrib);
}
return result;
#else
#if WINRT
Attribute[] all = System.Linq.Enumerable.ToArray(member.GetCustomAttributes(inherit));
#else
var all = member.GetCustomAttributes(inherit);
#endif
var result = new AttributeMap[all.Length];
for (var i = 0; i < all.Length; i++)
{
result[i] = new ReflectionAttributeMap((Attribute) all[i]);
}
return result;
#endif
}
示例8: HasCast
private static bool HasCast(TypeModel model, Type type, Type from, Type to, out MethodInfo op)
{
#if WINRT
System.Collections.Generic.List<MethodInfo> list = new System.Collections.Generic.List<MethodInfo>();
foreach (var item in type.GetRuntimeMethods())
{
if (item.IsStatic) list.Add(item);
}
MethodInfo[] found = list.ToArray();
#else
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo[] found = type.GetMethods(flags);
#endif
ParameterInfo[] paramTypes;
Type convertAttributeType = null;
for (int i = 0; i < found.Length; i++)
{
MethodInfo m = found[i];
if (m.ReturnType != to) continue;
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
if (convertAttributeType == null)
{
convertAttributeType = model.MapType(typeof(ProtoConverterAttribute), false);
if (convertAttributeType == null)
{ // attribute isn't defined in the source assembly: stop looking
break;
}
}
if (m.IsDefined(convertAttributeType, true))
{
op = m;
return true;
}
}
}
for(int i = 0 ; i < found.Length ; i++)
{
MethodInfo m = found[i];
if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
{
continue;
}
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
op = m;
return true;
}
}
op = null;
return false;
}
示例9: TypeSerializer
public TypeSerializer(TypeModel model, Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType, MethodInfo factory)
{
Helpers.Sort(fieldNumbers, serializers);
bool flag = false;
for (int i = 1; i < fieldNumbers.Length; i++)
{
if (fieldNumbers[i] == fieldNumbers[i - 1])
{
throw new InvalidOperationException("Duplicate field-number detected; " + fieldNumbers[i].ToString() + " on: " + forType.FullName);
}
if (!flag && serializers[i].ExpectedType != forType)
{
flag = true;
}
}
this.forType = forType;
this.factory = factory;
if (constructType == null)
{
constructType = forType;
}
else if (!forType.IsAssignableFrom(constructType))
{
throw new InvalidOperationException(forType.FullName + " cannot be assigned from " + constructType.FullName);
}
this.constructType = constructType;
this.serializers = serializers;
this.fieldNumbers = fieldNumbers;
this.callbacks = callbacks;
this.isRootType = isRootType;
this.useConstructor = useConstructor;
if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0)
{
baseCtorCallbacks = null;
}
this.baseCtorCallbacks = baseCtorCallbacks;
if (Helpers.GetUnderlyingType(forType) != null)
{
throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
}
if (model.MapType(TypeSerializer.iextensible).IsAssignableFrom(forType))
{
if (forType.IsValueType || !isRootType || flag)
{
throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
}
this.isExtensible = true;
}
this.hasConstructor = (!constructType.IsAbstract && Helpers.GetConstructor(constructType, Helpers.EmptyTypes, true) != null);
if (constructType != forType && useConstructor && !this.hasConstructor)
{
throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
}
}
示例10: SanityCheckCallback
private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback)
{
metaType.ThrowIfFrozen();
if (callback == null) return callback; // fine
if (callback.IsStatic) throw new ArgumentException("Callbacks cannot be static", "callback");
if (callback.ReturnType != model.MapType(typeof(void))
|| !CheckCallbackParameters(model, callback))
{
throw CreateInvalidCallbackSignature(callback);
}
return callback;
}
示例11: DefaultValueDecorator
public DefaultValueDecorator(TypeModel model, object defaultValue, IProtoSerializer tail)
: base(tail)
{
if (defaultValue == null)
{
throw new ArgumentNullException("defaultValue");
}
Type type = model.MapType(defaultValue.GetType());
if (type != tail.ExpectedType)
{
throw new ArgumentException("Default value is of incorrect type", "defaultValue");
}
this.defaultValue = defaultValue;
}
示例12: DefaultValueDecorator
public DefaultValueDecorator(TypeModel model, object defaultValue, IProtoSerializer tail) : base(tail)
{
if (defaultValue == null) throw new ArgumentNullException("defaultValue");
Type type = model.MapType(defaultValue.GetType());
if (type != tail.ExpectedType
#if FEAT_IKVM // in IKVM, we'll have the default value as an underlying type
&& !(tail.ExpectedType.IsEnum && type == tail.ExpectedType.GetEnumUnderlyingType())
#endif
)
{
throw new ArgumentException("Default value is of incorrect type", "defaultValue");
}
this.defaultValue = defaultValue;
}
示例13: TryCreate
public static ParseableSerializer TryCreate(Type type, TypeModel model)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
MethodInfo method = type.GetMethod("Parse", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public, null, new Type[]
{
model.MapType(typeof(string))
}, null);
if (method != null && method.ReturnType == type)
{
if (Helpers.IsValueType(type))
{
MethodInfo customToString = ParseableSerializer.GetCustomToString(type);
if (customToString == null || customToString.ReturnType != model.MapType(typeof(string)))
{
return null;
}
}
return new ParseableSerializer(method);
}
return null;
}
示例14: GetShadowSetter
static MethodInfo GetShadowSetter(TypeModel model, PropertyInfo property)
{
#if WINRT || COREFX
MethodInfo method = Helpers.GetInstanceMethod(property.DeclaringType.GetTypeInfo(), "Set" + property.Name, new Type[] { property.PropertyType });
#else
#if FEAT_IKVM
Type reflectedType = property.DeclaringType;
#else
Type reflectedType = property.ReflectedType;
#endif
MethodInfo method = Helpers.GetInstanceMethod(reflectedType, "Set" + property.Name, new Type[] { property.PropertyType });
#endif
if (method == null || !method.IsPublic || method.ReturnType != model.MapType(typeof(void))) return null;
return method;
}
示例15: NullDecorator
public NullDecorator(TypeModel model, IProtoSerializer tail)
: base(tail)
{
if (!tail.ReturnsValue)
throw new NotSupportedException("NullDecorator only supports implementations that return values");
if (Helpers.IsValueType(tail.ExpectedType))
{
#if NO_GENERICS
throw new NotSupportedException("NullDecorator cannot be used with a struct without generics support");
#else
expectedType = model.MapType(typeof(Nullable<>)).MakeGenericType(tail.ExpectedType);
#endif
}
else
{
expectedType = tail.ExpectedType;
}
}