Ejemplo n.º 1
0
 public static bool IsCandidateProperty(this PropertyInfo propertyInfo, bool needsWrite = true, bool publicOnly = true)
 => !propertyInfo.IsStatic() &&
 propertyInfo.CanRead &&
 (!needsWrite || propertyInfo.FindSetterProperty() != null) &&
 propertyInfo.GetMethod != null &&
 (!publicOnly || propertyInfo.GetMethod.IsPublic) &&
 propertyInfo.GetIndexParameters().Length == 0;
Ejemplo n.º 2
0
 public static bool IsCandidateProperty(this PropertyInfo propertyInfo, bool needsWrite = true)
 => !propertyInfo.IsStatic() &&
 propertyInfo.GetIndexParameters().Length == 0 &&
 propertyInfo.CanRead &&
 (!needsWrite || propertyInfo.CanWrite) &&
 propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic;
        /// <summary>
        /// Verifies that a field correctly exposes a certain parameter of a constructor.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        public override void Verify(PropertyInfo property)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            if (property.GetGetMethod() == null
                || property.IsStatic()
                || property.IsAbstract()
                || property.GetIndexParameters().Length != 0)
                return;

            var propertyInfoElement = property.ToElement();
            var parameterInfoElements = GetParameterInfoElements(property.ReflectedType);

            if (parameterInfoElements.Any(p => this.MemberToParameterComparer.Equals(propertyInfoElement, p)))
                return;

            var messageFormat = @"No constructors with an argument that matches the property were found.
            Declaring type: {0}
            Reflected type: {1}
            Property      : {2}";

            throw new MemberInitializationException(
                string.Format(
                    CultureInfo.CurrentCulture,
                    messageFormat,
                    property.DeclaringType,
                    property.ReflectedType,
                    propertyInfoElement));
        }
Ejemplo n.º 4
0
 public static bool IsCandidateProperty(this PropertyInfo propertyInfo)
 => !propertyInfo.IsStatic() &&
 propertyInfo.GetIndexParameters().Length == 0 &&
 propertyInfo.CanRead &&
 propertyInfo.CanWrite;
Ejemplo n.º 5
0
 /// <summary>
 /// Check the given type is a valid kRPC class property
 ///  1. Must have KRPCProperty attribute
 ///  2. Must have a valid identifier
 ///  3. Must be a public non-static property
 ///  4. Must be declared inside a kRPC class
 /// </summary>
 public static void ValidateKRPCClassProperty (PropertyInfo property)
 {
     if (!Reflection.HasAttribute<KRPCPropertyAttribute> (property))
         throw new ArgumentException (property + " does not have KRPCProperty attribute");
     // Note: Type must already be a property, due to AttributeUsage definition
     // Validate the identifier.
     ValidateIdentifier (property.Name);
     // Check it's not static
     if (!(property.IsPublic () && !property.IsStatic ()))
         throw new ServiceException ("KRPCProperty " + property + " is not public non-static");
     // Check the method is defined directly inside a KRPCClass
     var declaringType = property.DeclaringType;
     if (declaringType == null || !Reflection.HasAttribute<KRPCClassAttribute> (declaringType))
         throw new ServiceException ("KRPCProperty " + property + " is not declared inside a KRPCClass");
 }
Ejemplo n.º 6
0
 protected virtual PropertyInfo VisitProperty(PropertyInfo prop)
 {
     var origType = prop.DeclaringType;
     var replacedType = VisitType(origType);
     if (replacedType != origType)
     {
         return prop.IsStatic()
             ? replacedType.GetProperty(prop.Name,
                                        BindingFlags.Static | BindingFlags.NonPublic
                                        | BindingFlags.Public)
             : replacedType.GetProperty(prop.Name,
                                        BindingFlags.Instance | BindingFlags.NonPublic
                                        | BindingFlags.Public);
     }
     return prop;
 }
Ejemplo n.º 7
0
        public static IVariableDefinition CreateVariable(object instance, PropertyInfo property)
        {
            var variableType = typeof(VariableDefinition<>).MakeGenericType(property.PropertyType);
            IVariableDefinition variable = null;

            try
            {
                if (property.IsStatic())
                    variable = (IVariableDefinition)Activator.CreateInstance(variableType, null, property);
                else
                    variable = (IVariableDefinition)Activator.CreateInstance(variableType, instance, property);
            }
            catch { }

            return variable;
        }