public R2000ParameterInfoAttribute( R2000ParameterType parameterAccessType, R2000ProtocolVersion minVersion = R2000ProtocolVersion.Any, R2000ProtocolVersion maxVersion = R2000ProtocolVersion.Any) { this.AccessType = parameterAccessType; this.MinProtocolVersion = minVersion; this.MaxProtocolVersion = maxVersion; }
/// <summary> /// Get the list of "R2000 parameters" in this type /// </summary> /// <param name="type"></param> /// <returns></returns> public static string[] GetR2000ParametersList( this Type type, R2000ProtocolVersion protocolVersion, R2000ParameterType accessorTypes = R2000ParameterType.All) { var fieldNames = type.GetRuntimeProperties() // get only fields where we find a R2000ParameterTypeAttribute with the required filter .Where(field => { var parameterTypeAttribute = field.GetCustomAttributes <R2000ParameterInfoAttribute>(); if (!parameterTypeAttribute.Any()) { return(false); } var accessorsOk = parameterTypeAttribute.All(x => accessorTypes.HasFlag(x.AccessType)); var minVersionOk = parameterTypeAttribute.All(x => x.MinProtocolVersion == R2000ProtocolVersion.Any || x.MinProtocolVersion <= protocolVersion); var maxVersionOk = parameterTypeAttribute.All(x => x.MaxProtocolVersion == R2000ProtocolVersion.Any || x.MaxProtocolVersion >= protocolVersion); return(accessorsOk && minVersionOk && maxVersionOk); }) // select either the JsonProperty.PropertyName or the Fields true name as fallback .Select(field => { var jsonAttribute = field.GetCustomAttribute <JsonPropertyAttribute>(); if (jsonAttribute != null) { return(jsonAttribute.PropertyName); } else { return(field.Name); } }); return(fieldNames.ToArray()); }