예제 #1
0
        public CompiledPropertyAccessor(PropertyInfo property)
        {
            _setter = MakeSetter(property);
            _getter = MakeGetter(property);
            TypeInfo ti = property.PropertyType.GetTypeInfo();

            IsList = property.PropertyType != typeof(string) && typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(ti);


            Name        = property.Name;
            GenericType = property.PropertyType;
            if (IsList)
            {
                if (ti.IsArray)
                {
                    GenericType = ti.GetElementType();
                }
                else
                {
                    GenericType = ti.GenericTypeArguments.FirstOrDefault();
                }

                if (GenericType != null)
                {
                    ti = GenericType.GetTypeInfo();
                }
            }

            IsEnum = ti.IsEnum;
        }
예제 #2
0
            public TaskCompletionSourceInfo(Type resultType)
            {
                ResultType = resultType;
                Type tcsType = typeof(TaskCompletionSource <>);

                GenericType           = tcsType.MakeGenericType(new Type[] { resultType });
                TaskProperty          = GenericType.GetTypeInfo().GetDeclaredProperty("Task");
                TrySetResultMethod    = GenericType.GetTypeInfo().GetDeclaredMethod("TrySetResult");
                TrySetExceptionMethod = GenericType.GetRuntimeMethod("TrySetException", new Type[] { typeof(Exception) });
                TrySetCanceledMethod  = GenericType.GetRuntimeMethod("TrySetCanceled", Array.Empty <Type>());
            }
예제 #3
0
        public ProtoJsonPropertyAccessor(PropertyInfo p) : base(p)
        {
            // after base is initialized GenericType contains
            TypeInfo ti = GenericType.GetTypeInfo();

            ProtoMemberAttribute attribute = p.GetCustomAttribute <ProtoMemberAttribute>();

            if (attribute != null)
            {
                IsOptional = attribute.Optional;
                Position   = attribute.Position;
            }

            ProtoJsonType = AttributeTypeEnum.Value;

            if (IsEnum)
            {
                ProtoJsonType = AttributeTypeEnum.Enum;
            }
            else if (ti.IsDefined(typeof(ProtoContractAttribute), false))
            {
                ProtoJsonType = AttributeTypeEnum.ProtoContract;
            }
        }