private static bool TryGetWellKnownPrimitiveType(Type clrType, out PrimitiveType ptype) { ptype = null; if (!clrMapping.TryGetValue(clrType, out ptype) && IsBinaryType(clrType)) { ptype = clrMapping[typeof(BinaryTypeSub)]; } return (ptype != null); }
internal static bool TryGetPrimitiveType(string edmTypeName, out PrimitiveType ptype) { return edmMapping.TryGetValue(edmTypeName, out ptype); }
internal static bool TryGetPrimitiveType(Type clrType, out PrimitiveType ptype) { Type type = Nullable.GetUnderlyingType(clrType) ?? clrType; if (!TryGetWellKnownPrimitiveType(type, out ptype)) { KeyValuePair<Type, PrimitiveType>[] pairArray; lock (knownNonPrimitiveTypes) { if (knownNonPrimitiveTypes.Contains(clrType)) { ptype = null; return false; } } lock (derivedPrimitiveTypeMapping) { if (derivedPrimitiveTypeMapping.TryGetValue(clrType, out ptype)) { return true; } pairArray = (from m in clrMapping where !m.Key.IsPrimitive() && !m.Key.IsSealed() select m).Concat<KeyValuePair<Type, PrimitiveType>>(derivedPrimitiveTypeMapping).ToArray<KeyValuePair<Type, PrimitiveType>>(); } KeyValuePair<Type, PrimitiveType> pair = new KeyValuePair<Type, PrimitiveType>(typeof(object), null); foreach (KeyValuePair<Type, PrimitiveType> pair2 in pairArray) { if (type.IsSubclassOf(pair2.Key) && pair2.Key.IsSubclassOf(pair.Key)) { pair = pair2; } } if (pair.Value == null) { lock (knownNonPrimitiveTypes) { knownNonPrimitiveTypes.Add(clrType); } return false; } ptype = pair.Value; lock (derivedPrimitiveTypeMapping) { derivedPrimitiveTypeMapping[type] = ptype; } } return true; }
internal static void RegisterKnownType(Type clrType, string edmTypeName, EdmPrimitiveTypeKind primitiveKind, PrimitiveTypeConverter converter, bool twoWay) { PrimitiveType type = new PrimitiveType(clrType, edmTypeName, primitiveKind, converter, twoWay); clrMapping.Add(clrType, type); if (twoWay) { edmMapping.Add(edmTypeName, type); } }