Exemplo n.º 1
0
        //de-facto deprecated?
        //public SchemaType AsType<SchemaType>(SchemaType target)
        //{
        //    return AsType(this, target);
        //}

        public static SchemaType AsType <SchemaType>(Switch opts, SchemaType target)
        {
            Type schema = target.GetType();

            System.Reflection.BindingFlags filter = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.IgnoreCase;
            System.Reflection.MemberTypes  gauge  = System.Reflection.MemberTypes.Property | System.Reflection.MemberTypes.Field;
            foreach (KeyValuePair <string, string> named in opts.NamedArguments)
            {
                System.Reflection.MemberInfo[] member = schema.GetMember(named.Key, gauge, filter);
                if (member.Length == 0)
                {
                    continue;
                }
                Type   member_type = member[0].MemberType == System.Reflection.MemberTypes.Field ? (member[0] as System.Reflection.FieldInfo).FieldType : (member[0] as System.Reflection.PropertyInfo).PropertyType;
                string member_name = member[0].Name;
                ParseAndAssignValue(schema, target, opts, member_type, member_name, 1);
            }
            gauge = System.Reflection.MemberTypes.Method;
            foreach (KeyValuePair <string, string> named in opts.NamedArguments)
            {
                System.Reflection.MemberInfo[] member = schema.GetMember(named.Key, gauge, filter);
                if (member.Length == 0)
                {
                    continue;
                }
                schema.InvokeMember(member[0].Name, System.Reflection.BindingFlags.InvokeMethod, null, target, null);
            }
            return(target);
        }
 public InvalidMemberTypeException(
     Type @type,
     System.Reflection.MemberTypes memberType,
     string name,
     string message)
     : base(message)
 {
     AssociatedType = @type ?? throw new ArgumentNullException(nameof(@type));
     MemberType     = memberType;
     Name           = name ?? throw new ArgumentNullException(nameof(name));
 }
Exemplo n.º 3
0
        public JsonPropertyInfo <TProperty> CreateProperty <TProperty>(
            string clrPropertyName,
            System.Reflection.MemberTypes memberType,
            System.Type declaringType,
            JsonTypeInfo <TProperty> classInfo,
            JsonConverter converter,
            System.Func <object, TProperty> getter,
            System.Action <object, TProperty> setter,
            string jsonPropertyName,
            byte[] nameAsUtf8Bytes,
            byte[] escapedNameSection,
            JsonIgnoreCondition?ignoreCondition,
            JsonNumberHandling?numberHandling)
        {
            JsonSerializerOptions        options          = GetOptions();
            JsonPropertyInfo <TProperty> jsonPropertyInfo = JsonPropertyInfo <TProperty> .Create();

            jsonPropertyInfo.Options = options;
            // Property name settings.
            // TODO: consider whether we need to examine options.Encoder here as well.
            if (options.PropertyNamingPolicy == null && nameAsUtf8Bytes != null && escapedNameSection != null)
            {
                jsonPropertyInfo.NameAsString       = jsonPropertyName ?? clrPropertyName;
                jsonPropertyInfo.NameAsUtf8Bytes    = nameAsUtf8Bytes;
                jsonPropertyInfo.EscapedNameSection = escapedNameSection;
            }
            else
            {
                jsonPropertyInfo.NameAsString = jsonPropertyName
                                                ?? options.PropertyNamingPolicy?.ConvertName(clrPropertyName)
                                                ?? (options.PropertyNamingPolicy == null
                            ? null
                            : throw new System.InvalidOperationException("TODO: PropertyNamingPolicy cannot return null."));
                // NameAsUtf8Bytes and EscapedNameSection will be set in CompleteInitialization() below.
            }
            if (ignoreCondition != JsonIgnoreCondition.Always)
            {
                jsonPropertyInfo.Get                  = getter;
                jsonPropertyInfo.Set                  = setter;
                jsonPropertyInfo.ConverterBase        = converter ?? throw new System.NotSupportedException("TODO: need custom converter here?");
                jsonPropertyInfo.RuntimeClassInfo     = classInfo;
                jsonPropertyInfo.DeclaredPropertyType = typeof(TProperty);
                jsonPropertyInfo.DeclaringType        = declaringType;
                jsonPropertyInfo.IgnoreCondition      = ignoreCondition;
                jsonPropertyInfo.MemberType           = memberType;
            }
            jsonPropertyInfo.CompleteInitialization();
            return(jsonPropertyInfo);
        }
 public virtual System.Reflection.MemberInfo[] GetMember(string name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr)
 {
 }
 public virtual System.Reflection.MemberInfo[] FindMembers(System.Reflection.MemberTypes memberType, System.Reflection.BindingFlags bindingAttr, System.Reflection.MemberFilter filter, object filterCriteria)
 {
 }
Exemplo n.º 6
0
 public override System.Reflection.MemberInfo[] GetMember(string name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr)
 {
     throw new PlatformNotSupportedException();
 }
Exemplo n.º 7
0
 public System.Reflection.MemberInfo[] GetMember(string name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr)
 {
     return(default(System.Reflection.MemberInfo[]));
 }
Exemplo n.º 8
0
 public LazyMemberInfo(System.Reflection.MemberTypes memberType, Func <System.Reflection.MemberInfo[]> accessorsCreator)
 {
 }
Exemplo n.º 9
0
 public LazyMemberInfo(System.Reflection.MemberTypes memberType, System.Reflection.MemberInfo[] accessors)
 {
 }
 public static System.Reflection.MemberTypes RemoveFlag(this System.Reflection.MemberTypes self, System.Reflection.MemberTypes flag)
 {
     return(self & ~flag);
 }
 public static System.Reflection.MemberTypes AddFlag(this System.Reflection.MemberTypes self, System.Reflection.MemberTypes flag)
 {
     return(self | flag);
 }
 public static bool HasAnyFlag(this System.Reflection.MemberTypes self, System.Reflection.MemberTypes flags)
 {
     return((self & flags) > 0);
 }
 public static bool HasFlag(this System.Reflection.MemberTypes self, System.Reflection.MemberTypes flag)
 {
     return((self & flag) == flag);
 }
Exemplo n.º 14
0
 public virtual new System.Reflection.MemberInfo[] FindMembers(System.Reflection.MemberTypes memberType, System.Reflection.BindingFlags bindingAttr, System.Reflection.MemberFilter filter, Object filterCriteria)
 {
     return(default(System.Reflection.MemberInfo[]));
 }