Beispiel #1
0
        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();
        }
Beispiel #3
0
        /// <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));
 }
Beispiel #6
0
        public virtual SshContract ResolveContract(Type type)
        {
            ValidationUtils.ArgumentNotNull(type, nameof(type));

            return(_contractCache.Get(type));
        }
Beispiel #7
0
 public static T GetAttribute(object type)
 {
     return(TypeAttributeCache.Get(type));
 }
Beispiel #8
0
 private static Type GetTypeConverterType(ICustomAttributeProvider attributeProvider)
 {
     return(TypeConverterTypeCache.Get(attributeProvider));
 }
Beispiel #9
0
 public static Attribute[] GetCachedAttributes(this ICustomAttributeProvider type) => Cache.Get(Ensure.NotNull(type, nameof(type)));
 private static ProjectionInfo GetProjectionInfo(ISpatialReference spatialReference)
 {
     return(Infos.Get(spatialReference));
 }
Beispiel #11
0
        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));
 }
Beispiel #16
0
 private static Type GetAssociatedMetadataType(Type type)
 {
     return(AssociatedMetadataTypesCache.Get(type));
 }
Beispiel #17
0
 /// <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)));
 }
Beispiel #19
0
 public static MySerializer GetSerializer(Type t)
 {
     return(m_serializers.Get(t));
 }
 private static Type GetJsonConverterType(object attributeProvider)
 {
     return(JsonConverterTypeCache.Get(attributeProvider));
 }
Beispiel #21
0
 private IGeometryFactory GetFactory(ISpatialReference spatialReference)
 {
     return(_factories.Get(spatialReference));
 }