internal bool TryGetMember(IDynamicMetaObjectProvider dynamicProvider, string name, out object value) { ValidationUtils.ArgumentNotNull(dynamicProvider, "dynamicProvider"); CallSite <Func <CallSite, object, object> > callSite = _callSiteGetters.Get(name); object result = callSite.Target(callSite, dynamicProvider); if (!ReferenceEquals(result, NoThrowExpressionVisitor.ErrorResult)) { value = result; return(true); } else { value = null; return(false); } }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } DefaultContractResolver?resolver = serializer.ContractResolver as DefaultContractResolver; Type unionType = UnionTypeLookupCache.Get(value.GetType()); Union union = UnionCache.Get(unionType); int tag = (int)union.TagReader.Invoke(value); UnionCase caseInfo = union.Cases.Single(c => c.Tag == tag); writer.WriteStartObject(); writer.WritePropertyName( (resolver != null) ? resolver.GetResolvedPropertyName(CasePropertyName) : CasePropertyName ); writer.WriteValue(caseInfo.Name); if (caseInfo.Fields != null && caseInfo.Fields.Length > 0) { object[] fields = (object[])caseInfo.FieldReader.Invoke(value) !; writer.WritePropertyName( (resolver != null) ? resolver.GetResolvedPropertyName(FieldsPropertyName) : FieldsPropertyName ); writer.WriteStartArray(); foreach (object field in fields) { serializer.Serialize(writer, field); } writer.WriteEndArray(); } writer.WriteEndObject(); }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver; Type unionType = UnionTypeLookupCache.Get(value.GetType()); Union union = UnionCache.Get(unionType); int tag = union.TagReader(value); UnionCase caseInfo = union.Cases.Single(c => c.Tag == tag); writer.WriteStartObject(); writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(CasePropertyName) : CasePropertyName); writer.WriteValue(caseInfo.Name); if (caseInfo.Fields != null && caseInfo.Fields.Length > 0) { object[] fields = caseInfo.FieldReader(value); writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(FieldsPropertyName) : FieldsPropertyName); serializer.Serialize(writer, fields); } writer.WriteEndObject(); }
public static T GetAttribute(ICustomAttributeProvider type) { return(TypeAttributeCache.Get(type)); }
private Type GetTypeByName(TypeNameKey typeNameKey) { return(_typeCache.Get(typeNameKey)); }
public virtual SshContract ResolveContract(Type type) { ValidationUtils.ArgumentNotNull(type, nameof(type)); return(_contractCache.Get(type)); }
public static T GetAttribute(object type) { return(TypeAttributeCache.Get(type)); }
private static Type GetTypeConverterType(ICustomAttributeProvider attributeProvider) { return(TypeConverterTypeCache.Get(attributeProvider)); }
public static Attribute[] GetCachedAttributes(this ICustomAttributeProvider type) => Cache.Get(Ensure.NotNull(type, nameof(type)));
private static ProjectionInfo GetProjectionInfo(ISpatialReference spatialReference) { return(Infos.Get(spatialReference)); }
internal bool TrySetMember(IDynamicMetaObjectProvider dynamicProvider, string name, object value) { ValidationUtils.ArgumentNotNull(dynamicProvider, nameof(dynamicProvider)); CallSite <Serialization.Func <CallSite, object, object, object> > callSite = _callSiteSetters.Get(name); object result = callSite.Target(callSite, dynamicProvider, value); return(!ReferenceEquals(result, NoThrowExpressionVisitor.ErrorResult)); }
public static IGeometryFactory CreateGeometryFactory(this IGeometryServices self, string oid) { return(_store.Get(oid)); }
private static Type GetAssociatedMetadataType(Type type) => AssociatedMetadataTypesCache.Get(type);
public static JsonConverter CreateJsonConverterInstance(Type converterType, object[] converterArgs) => ((JsonConverter)CreatorCache.Get(converterType)(converterArgs));
private Type GetTypeByName(StructMultiKey <string, string> typeNameKey) { return(_typeCache.Get(typeNameKey)); }
private static Type GetAssociatedMetadataType(Type type) { return(AssociatedMetadataTypesCache.Get(type)); }
/// <summary> /// Resolves the contract for a given type. /// </summary> /// <param name="type">The type to resolve a contract for.</param> /// <returns>The contract for a given type.</returns> public virtual JsonContract ResolveContract(Type type) { return(_typeContractCache.Get(type)); }
/// <summary> /// When overridden in a derived class, controls the binding of a serialized object to a type. /// </summary> /// <param name="assemblyName">Specifies the <see cref="T:System.Reflection.Assembly"/> name of the serialized object.</param> /// <param name="typeName">Specifies the <see cref="T:System.Type"/> name of the serialized object.</param> /// <returns> /// The type of the object the formatter creates a new instance of. /// </returns> public override Type BindToType(string assemblyName, string typeName) { return(_typeCache.Get(new TypeNameKey(assemblyName, typeName))); }
public static MySerializer GetSerializer(Type t) { return(m_serializers.Get(t)); }
private static Type GetJsonConverterType(object attributeProvider) { return(JsonConverterTypeCache.Get(attributeProvider)); }
private IGeometryFactory GetFactory(ISpatialReference spatialReference) { return(_factories.Get(spatialReference)); }